Skip to main content

BetterE2B - Drop-in replacement for e2b-code-interpreter with dynamic subdomain support

Project description

๐ŸŽฏ BetterE2B SDK

Drop-in replacement for @e2b/code-interpreter with dynamic subdomain support!

๐Ÿš€ Features

  • โœ… 100% E2B Compatible - Same API as official E2B
  • โœ… Dynamic Subdomains - https://{port}-{id}.yourdomain.com
  • โœ… Path-based Routing - yourdomain.com/{port}-{id}/
  • โœ… JavaScript/TypeScript SDK - bettere2b
  • โœ… Python SDK - bettere2b
  • โœ… Auto-managed Lifecycle - Context managers and cleanup
  • โœ… No API Key Required - Works out of the box

๐Ÿ“ฆ Installation

JavaScript/TypeScript

npm install bettere2b

Python

pip install bettere2b

๐ŸŽฏ Quick Start

JavaScript/TypeScript

import { Sandbox } from 'bettere2b'

const sandbox = await Sandbox.create()
await sandbox.runCode('x = 1')

const execution = await sandbox.runCode('x+=1; x')
console.log(execution.text)  // outputs 2

// Get dynamic subdomain URL
console.log(sandbox.getSubdomainUrl()) // https://8083-uuid.yourdomain.com

await sandbox.kill()

Python

from bettere2b import Sandbox

with Sandbox.create() as sandbox:
    sandbox.run_code("x = 1")
    execution = sandbox.run_code("x+=1; x")
    print(execution.text)  # outputs 2
    
    # Get dynamic subdomain URL
    print(sandbox.get_subdomain_url())  # https://8083-uuid.yourdomain.com

๐Ÿ”„ Migration from Official E2B

Replace this:

import { Sandbox } from '@e2b/code-interpreter'

With this:

import { Sandbox } from 'bettere2b'

That's it! Your existing code will work without any changes.

๐ŸŒ Dynamic Subdomain Features

Get Subdomain URL

const sandbox = await Sandbox.create()
const subdomainUrl = sandbox.getSubdomainUrl()
// Returns: https://8083-uuid.yourdomain.com

Get Path-based URL

const pathUrl = sandbox.getPathUrl()
// Returns: https://yourdomain.com/8083-uuid/

Get Subdomain Configuration

const config = await sandbox.getSubdomainConfig()
console.log(config.urls.subdomain)  // Full subdomain URL
console.log(config.urls.path)       // Path-based URL

๐Ÿ“š API Reference

Sandbox Methods

Method Description E2B Compatible
Sandbox.create(options) Create new sandbox โœ…
sandbox.runCode(code, language) Execute code โœ…
sandbox.kill() Terminate sandbox โœ…
sandbox.getHost(port) Get host URL โœ…
sandbox.install(packages, manager) Install packages โœ…
sandbox.writeFile(path, content) Write file โœ…
sandbox.readFile(path) Read file โœ…
sandbox.listFiles(directory) List files โœ…
sandbox.setTimeout(ms) Set timeout โœ…
sandbox.extendTimeout(ms) Extend timeout โœ…
sandbox.getSubdomainUrl() Get subdomain URL ๐Ÿ†•
sandbox.getPathUrl() Get path URL ๐Ÿ†•
sandbox.getSubdomainConfig() Get subdomain config ๐Ÿ†•

ExecutionResult

const result = await sandbox.runCode('print("Hello")')
console.log(result.text)        // Output text
console.log(result.logs.stdout) // stdout logs
console.log(result.logs.stderr) // stderr logs
console.log(result.error)       // Error message
console.log(result.exitCode)    // Exit code
console.log(result.executionTime) // Execution time

๐Ÿ”ง Configuration

Server URL

const sandbox = await Sandbox.create({
  serverUrl: 'http://localhost:8083'  // Your E2B clone server
})

API Key (Optional)

const sandbox = await Sandbox.create({
  apiKey: 'your-api-key'  // If your server requires authentication
})

Runtime Options

const sandbox = await Sandbox.create({
  name: 'My Sandbox',
  runtime: 'react',  // static, react, python, nextjs, etc.
  description: 'My custom sandbox',
  timeout: 60 * 60 * 1000  // 1 hour timeout
})

๐Ÿงช Testing

JavaScript

cd server/sdk/javascript
npm test

Python

cd server/sdk/python
python test.py

๐Ÿ†š Comparison with Official E2B

Feature Official E2B Your E2B Clone
Sandbox Creation โœ… โœ…
Code Execution โœ… โœ…
File Operations โœ… โœ…
Package Installation โœ… โœ…
Timeout Management โœ… โœ…
Dynamic Subdomains โŒ โœ…
Path-based Routing โŒ โœ…
Self-hosted โœ… โœ…
No API Key Required โŒ โœ…
Free to Use โŒ โœ…

๐Ÿš€ Advanced Features

Context Manager (Python)

with Sandbox.create() as sandbox:
    result = sandbox.run_code('print("Hello")')
    # Sandbox automatically killed when exiting context

Quick Create Function

from your_e2b_clone import create_sandbox

sandbox = create_sandbox(name='Quick Test')

Multiple Language Support

// Python
await sandbox.runCode('print("Hello")', 'python')

// JavaScript
await sandbox.runCode('console.log("Hello")', 'javascript')

// Bash
await sandbox.runCode('echo "Hello"', 'bash')

๐Ÿ”— Links

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿค Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details.


Made with โค๏ธ - Your E2B Clone SDK

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bettere2b-1.0.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bettere2b-1.0.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file bettere2b-1.0.0.tar.gz.

File metadata

  • Download URL: bettere2b-1.0.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.12.1.2 readme-renderer/44.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/2.2.3 tqdm/4.67.1 importlib-metadata/8.7.0 keyring/25.6.0 rfc3986/1.5.0 colorama/0.4.6 CPython/3.11.9

File hashes

Hashes for bettere2b-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2f84df3cb41998f82e88589b29615ea3d1654b627b9b7da588065c42cbe1d17f
MD5 f7dab352c23bd23e8e89664b6ab52d1c
BLAKE2b-256 d02cfef34d2a79a76d3c87691b502ec5ac302cf3c5f73605729924308ef3678e

See more details on using hashes here.

File details

Details for the file bettere2b-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: bettere2b-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.12.1.2 readme-renderer/44.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/2.2.3 tqdm/4.67.1 importlib-metadata/8.7.0 keyring/25.6.0 rfc3986/1.5.0 colorama/0.4.6 CPython/3.11.9

File hashes

Hashes for bettere2b-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a46f07c7ed28e7238df0ed4d8fa4f5c181a8e80c5b0094be62af7f0211c2ad4
MD5 79ed185e0e6c68cd612eee1eaac380d0
BLAKE2b-256 c45122d0e2d25f6b4bb2033cf73293958fb56f0f8fd7571a2f766efb99ca5dd2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page