e2b-sandbox
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseE2B Sandboxes with ComputeSDK
E2B沙箱与ComputeSDK
Run code in E2B's Firecracker microVMs through ComputeSDK's unified API. E2B provides sub-second cold starts and secure isolation — ideal for AI code execution, data science, and educational platforms.
通过ComputeSDK的统一API在E2B的Firecracker microVM中运行代码。E2B提供亚秒级冷启动和安全隔离——非常适合AI代码执行、数据科学和教育平台。
Setup
安装配置
bash
npm install computesdkbash
undefinedbash
npm install computesdkbash
undefined.env
.env
COMPUTESDK_API_KEY=your_computesdk_api_key
E2B_API_KEY=your_e2b_api_key
Get your ComputeSDK key at https://console.computesdk.com/registerCOMPUTESDK_API_KEY=your_computesdk_api_key
E2B_API_KEY=your_e2b_api_key
前往https://console.computesdk.com/register获取你的ComputeSDK密钥Quick Start
快速开始
typescript
import { compute } from 'computesdk';
// Auto-detects E2B from environment variables
const sandbox = await compute.sandbox.create();
const result = await sandbox.runCode('print("Hello from E2B!")');
console.log(result.output);
await sandbox.destroy();typescript
import { compute } from 'computesdk';
// 从环境变量中自动检测E2B配置
const sandbox = await compute.sandbox.create();
const result = await sandbox.runCode('print("Hello from E2B!")');
console.log(result.output);
await sandbox.destroy();Explicit Configuration
显式配置
For multi-provider setups or when you want to be explicit:
typescript
import { compute } from 'computesdk';
compute.setConfig({
computesdkApiKey: process.env.COMPUTESDK_API_KEY,
provider: 'e2b',
e2b: {
apiKey: process.env.E2B_API_KEY,
}
});
const sandbox = await compute.sandbox.create();适用于多提供商设置或需要明确指定配置的场景:
typescript
import { compute } from 'computesdk';
compute.setConfig({
computesdkApiKey: process.env.COMPUTESDK_API_KEY,
provider: 'e2b',
e2b: {
apiKey: process.env.E2B_API_KEY,
}
});
const sandbox = await compute.sandbox.create();E2B Configuration Options
E2B配置选项
typescript
interface E2BConfig {
apiKey?: string; // Uses E2B_API_KEY env var if not set
runtime?: 'node' | 'python'; // Auto-detects from code patterns
timeout?: number; // Execution timeout in ms
}typescript
interface E2BConfig {
apiKey?: string; // 如果未设置,则使用E2B_API_KEY环境变量
runtime?: 'node' | 'python'; // 从代码模式自动检测
timeout?: number; // 执行超时时间(毫秒)
}Runtime Detection
运行时检测
E2B auto-detects Python from statements, , , and Python-specific syntax like . All other code defaults to Node.js.
printimportdeff"strings"E2B会从语句、、以及Python特定语法如自动检测Python代码。所有其他代码默认使用Node.js。
printimportdeff"strings"Full API
完整API
ComputeSDK provides the same API across all providers: filesystem operations, shell commands, managed servers, overlays, terminals, and client access.
Install the main skill for the complete reference:
npx skills add https://github.com/computesdk/sandbox-skills --skill computesdkComputeSDK在所有提供商中提供统一的API:文件系统操作、Shell命令、托管服务器、覆盖层、终端和客户端访问。
安装主技能以获取完整参考:
npx skills add https://github.com/computesdk/sandbox-skills --skill computesdk