从 E2B 迁移
SeaCloud Sandbox 保留开发者熟悉的沙箱概念,同时使用 SeaCloud 的 Gateway 鉴权、模板引用、运行时 Token 和公网端口 URL。
| 运行时 | E2B 包 | SeaCloud 包 |
|---|---|---|
| Node | @e2b/code-interpreter 或 e2b | @seacloudai/sandbox |
| Python | e2b-code-interpreter 或 e2b | seacloud-sandbox |
| Go | E2B 客户端包 | github.com/SeaCloudAI/sandbox-go |
| 用途 | E2B | SeaCloud |
|---|---|---|
| API Token | E2B_API_KEY | SEACLOUD_API_KEY |
| API Host | 通常使用 SDK 默认值 | SEACLOUD_BASE_URL=https://sandbox-gateway.cloud.seaart.ai |
| 运行时 Token | SDK 隐藏 | envdAccessToken,创建或重连后由 SDK 隐藏 |
API 映射
Section titled “API 映射”| E2B 概念 | SeaCloud 对应能力 | 说明 |
|---|---|---|
Sandbox.create() / new Sandbox() | 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) | 生命周期超时单位是秒。 |
| Commands | sandbox.commands.run(cmd, options) | 运行时命令超时字段为毫秒级 timeoutMs。 |
| Filesystem | sandbox.files.read/write/list/makeDir | 生产示例建议使用绝对路径。 |
| Host URL | sandbox.getHost(port) | 返回 https://{port}-{sandboxID}.{domain}/。 |
| Code interpreter | sandbox.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: SeaCloudimport { Sandbox } from "@seacloudai/sandbox";
const sandbox = await Sandbox.create("base", { 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();}# Before: E2B-style# sandbox = Sandbox.create()# result = sandbox.commands.run("echo hello")# sandbox.kill()
# After: SeaCloudfrom sandbox import Sandbox
sandbox = Sandbox.create("base", timeout=1800, waitReady=True)
try: result = sandbox.commands.run( "sh", args=["-lc", "echo hello"], timeout_ms=30_000, ) print(result["stdout"])finally: sandbox.delete()迁移检查清单
Section titled “迁移检查清单”- 替换包名和环境变量。
- 选择显式模板:命令/文件用
base,runCode用code-interpreter,生产环境用具体tpl-...。 - 将 kill/close 调用替换为一次性任务的
delete(),或可恢复任务的pause()。 - 检查超时单位:沙箱生命周期
timeout是秒,命令timeoutMs是毫秒。 - 使用 SDK 时用
getHost(port)替代手拼应用 URL。 - 不要把
envdAccessToken写进日志或客户端代码。