跳转到内容
返回主页

从 E2B 迁移

SeaCloud Sandbox 保留开发者熟悉的沙箱概念,同时使用 SeaCloud 的 Gateway 鉴权、模板引用、运行时 Token 和公网端口 URL。

运行时E2B 包SeaCloud 包
Node@e2b/code-interpretere2b@seacloudai/sandbox
Pythone2b-code-interpretere2bseacloud-sandbox
GoE2B 客户端包github.com/SeaCloudAI/sandbox-go
用途E2BSeaCloud
API TokenE2B_API_KEYSEACLOUD_API_KEY
API Host通常使用 SDK 默认值SEACLOUD_BASE_URL=https://sandbox-service.real-cloud.seaart.ai/api/v1/sandbox
运行时 TokenSDK 隐藏envdAccessToken,创建或重连后由 SDK 隐藏
E2B 概念SeaCloud 对应能力说明
Sandbox.create() / new Sandbox()Sandbox.create(options)Sandbox.create(templateID, options)SeaCloud 不传模板时默认使用 base。需要特定环境时再传 code-interpreter 或具体 tpl-...
Sandbox.connect(id)Sandbox.connect(id, options)重连会从控制面刷新运行时 URL/Token。
sandbox.kill() / sandbox.close()sandbox.delete()一次性任务用删除;需要恢复时用 pause()
sandbox.setTimeout(...)sandbox.setTimeout(seconds)生命周期超时单位是秒。
Commandssandbox.commands.run(cmd, options)运行时命令超时字段为毫秒级 timeoutMs
Filesystemsandbox.files.read/write/list/makeDir生产示例建议使用绝对路径。
Host URLsandbox.getHost(port)返回基于 envdUrl 的代理 URL;原始端口路由是 https://sandbox-router.cloud.seaart.ai/{port}-{sandboxID}/
Code interpretersandbox.runCode(...) / run_code(...)使用 code-interpreter 模板。
// Before: E2B-style
// const sandbox = await Sandbox.create();
// const result = await sandbox.commands.run("echo hello");
// await sandbox.kill();
// After: SeaCloud。不传模板时使用 base。
import { Sandbox } from "@seacloudai/sandbox";
const sandbox = await Sandbox.create({
timeout: 1800,
waitReady: true,
});
try {
const result = await sandbox.commands.run("sh", {
args: ["-lc", "echo hello"],
timeoutMs: 30_000,
});
console.log(result.stdout);
} finally {
await sandbox.delete();
}
  1. 替换包名和环境变量。
  2. 基础命令/文件可使用默认 baserunCodecode-interpreter,生产环境传具体 tpl-...
  3. 将 kill/close 调用替换为一次性任务的 delete(),或可恢复任务的 pause()
  4. 检查超时单位:沙箱生命周期 timeout 是秒,命令 timeoutMs 是毫秒。
  5. 使用 SDK 时用 getHost(port) 替代手拼应用 URL。
  6. 不要把 envdAccessToken 写进日志或客户端代码。