E2B
E2B provider for ComputeSDK - Execute code in full development environments with terminal support.
Installation
Section titled “Installation”npm install @computesdk/e2bWith ComputeSDK
Section titled “With ComputeSDK”import { createCompute } from 'computesdk';
import { e2b } from '@computesdk/e2b';
// Set as default provider
const compute = createCompute({
provider: e2b({ apiKey: process.env.E2B_API_KEY }),
apiKey: process.env.COMPUTESDK_API_KEY
});
// Create sandbox
const sandbox = await compute.sandbox.create();
// Get instance
const instance = sandbox.getInstance();
// Execute code
const result = await sandbox.runCode('print("Hello from E2B!")');
console.log(result.stdout); // "Hello from E2B!"
// Clean up
await compute.sandbox.destroy(sandbox.sandboxId);Configuration
Section titled “Configuration”Environment Variables
Section titled “Environment Variables”export E2B_API_KEY=e2b_your_api_key_hereConfiguration Options
Section titled “Configuration Options”interface E2BConfig {
/** E2B API key - if not provided, will use E2B_API_KEY env var */
apiKey?: string;
/** Environment template to use */
runtime?: 'node' | 'python';
/** Execution timeout in milliseconds */
timeout?: number;
}Runtime Detection
Section titled “Runtime Detection”The provider automatically detects the runtime based on code patterns:
Python indicators:
printstatementsimportstatementsdeffunction definitions- Python-specific syntax (
f",__, etc.)
Default: Node.js for all other cases
SDK Reference Links:
Section titled “SDK Reference Links:”- Code Execution - Execute code snippets in various runtimes
- Command Execution - Run shell commands and scripts
- Filesystem Operations - Read, write, and manage files in sandboxes
- Sandbox Management - Create, list, and destroy sandboxes
- Error Handling - Handle command failures and runtime errors
- Web Framework Integration - Integrate with Express, Next.js, and other frameworks