E2B 兼容性与差异参考
本参考页归纳官方 E2B SDK 与 CubePod Gateway(cubepod-gateway)在下列已核对接口上的兼容性与行为差异,并不是对上游 E2B API 或 SDK 表面的完整清单审计。
CubePod 实现了核心 E2B REST 与 Connect-RPC 端点,允许使用官方 E2B 客户端 SDK 的团队将流量重定向至私有化部署的 CubePod 实例。然而,CubePod 并非托管版 E2B Cloud 的逐行克隆:它构建在基于 Kata Containers 微虚拟机的双块卷持久化架构之上,具备不同的生命周期语义、双卷存储模型与面向企业部署的扩展接口。
架构分层定义
Section titled “架构分层定义”在评估兼容性时,必须严格区分三个不同的技术层面,绝不能将它们混为一谈:
+---------------------------------------------------------------------------------------+| 第 1 层:官方 E2B SDK 接入层(Official E2B SDK Drop-in) || 未经修改的上游官方客户端包('e2b'、'e2b-code-interpreter'、'@e2b/code-interpreter') || 通过 E2B_DOMAIN 或 E2B_API_URL + E2B_SANDBOX_URL + E2B_API_KEY 指向 CubePod |+---------------------------------------------------------------------------------------+ | v+---------------------------------------------------------------------------------------+| 第 3 层:网关协议与线级转译层(Protocol & Gateway Wire Translation) || 'cubepod-gateway'(:8080)REST 路由与 Connect-RPC 处理器 || 转译 /sandboxes、/process.Process/*、/filesystem.Filesystem/*、/templates 等协议 |+---------------------------------------------------------------------------------------+ ^ |+---------------------------------------------------------------------------------------+| 第 2 层:CubePod 原生 SDK 层(功能类似超集客户端) || 命名为 'cubepod' 的原生 SDK('sdks/python/'、'sdks/typescript/'、'pkg/client') || 绝非 'from e2b import Sandbox' 的代码别名;提供 fork、reset-rootfs、面板与凭据隔离超集 |+---------------------------------------------------------------------------------------+- 第 1 层:官方 E2B SDK 接入层(Official E2B SDK Drop-in):
专指直接使用上游官方 Python 包(
e2b、e2b-code-interpreter)或 npm 包(@e2b/code-interpreter、e2b),通过配置环境变量将请求目标指向 CubePod。这是唯一可被称为“官方 SDK 兼容性”的技术层面。 - 第 2 层:CubePod 原生 SDK 层(功能重叠与超集客户端):
cubepod官方客户端库(sdks/python/与sdks/typescript/,以及位于pkg/client的 Go 客户端与cmd/cubepodCLI)提供了现代化的沙箱操作句柄(.commands、.files、.code)。但是,它们是原生客户端,并非from e2b import Sandbox的平替别名。它们直接调用 CubePod 原生/sandboxes/{id}/*接口,并开放 CubePod 专属的企业级特性(fork、reset-rootfs、archive-sync、secretBindings、桌面与面板代理)。 - 第 3 层:网关协议与路由实现层(Gateway Protocol Route Presence):
在
cubepod-gateway(pkg/gateway/server.go与pkg/gateway/connectrpc.go)中注册了 HTTP REST 或 Connect-RPC 路由,说明代码中存在对应的协议转译逻辑。然而,单纯存在路由并不意味着上游 SDK 的所有版本和边界方法都已在生产环境中完成无缝互通。
将官方 E2B SDK 指向 CubePod
Section titled “将官方 E2B SDK 指向 CubePod”官方 E2B SDK 可以通过标准环境变量重定向至 cubepod-gateway:
生产环境 HTTPS + 通配符 DNS Ingress
Section titled “生产环境 HTTPS + 通配符 DNS Ingress”当 cubepod-gateway 部署在具备通配符 DNS(*.<E2B_DOMAIN>)的 Ingress Controller 后方时:
export E2B_DOMAIN="cubepod.example.com"export E2B_API_KEY="cpod_live_secret"上游 E2B SDK 会自动将控制面请求发往 api.<E2B_DOMAIN>(或根域名),并将沙箱端口访问路由至 <port>-<sandboxID>.<E2B_DOMAIN>。cubepod-gateway 通过匹配 Host 请求头的 ^([0-9]+)-([a-zA-Z0-9_-]+)\.(.*)$ 自动将流量精准反向代理至沙箱微虚拟机。
本地直连 HTTP / 直连网关
Section titled “本地直连 HTTP / 直连网关”在本地开发调试且未配置 TLS 与通配符 DNS 时(如连接 http://127.0.0.1:8080):
export E2B_API_URL="http://127.0.0.1:8080"export E2B_SANDBOX_URL="http://127.0.0.1:8080"export E2B_API_KEY="cpod_test_api_key"同时设置 E2B_API_URL 与 E2B_SANDBOX_URL 会强制 SDK 将控制面与数据面流量均直接发往指定的 Gateway 地址。这也是仓库 test/e2b-compat/ 自动化测试所采用的配置。
接口兼容性矩阵
Section titled “接口兼容性矩阵”- 兼容(Compatible):
test/e2b-compat/中对应的官方 Python SDK 测试用例已覆盖下列基本场景。这不表示所有参数或边界均已实现或测过,也不表示编写本页时重新跑过这些测试。 - 部分兼容(Partial):已有对应处理器或协议路径,但存在已知缺漏、语义差异或需要打开特性开关。
- 未测试(Untested):可能存在代码路径或路由,或官方 SDK 助手并不依赖 CubePod 专用路由,但本仓库没有覆盖该官方 SDK 方法的自动化测试。
- 未支持(Unsupported):未找到对应的 CubePod 处理器、路由或等价协议支持,且该上游能力不仅仅是对另一项已覆盖 API 的 SDK 包装。
表格中的 e2b>=2.0.0 一类写法是 test/e2b-compat/run_tests.sh 声明的依赖下限(模板套件还会断言已安装包的主版本 >= 2),不是已测版本的全集,也不是本次文档更新时的实测结果。
1. 沙箱生命周期(Sandbox Lifecycle)
Section titled “1. 沙箱生命周期(Sandbox Lifecycle)”| 官方 E2B 接口 | CubePod 网关路由 / 协议 | 状态 | 代码证据 / 实现指针 | 仓库测试声明 / 版本约束 | 行为差异与限制说明 |
|---|---|---|---|---|---|
Sandbox.create(...) [Python] |
POST /sandboxesPOST /v2/sandboxes |
兼容 | pkg/gateway/sandboxes.go:handleCreateSandboxtest/e2b-compat/test_official_e2b_sync.pytest/e2b-compat/test_official_e2b_async.pytest/e2b-compat/test_concurrent_sandboxes_isolation.py |
e2b>=2.0.0(依赖下限,非已测版本全集) |
创建响应会填充所列 E2B 必填字段(sandboxID、templateID、clientID、envdVersion、state、startedAt、endAt、cpuCount、memoryMB、diskSizeMB)。若存在可用的 PodWarmPool 备用实例,网关可以认领预热 Pod;认领耗时取决于集群与存储,本页不给出测量过的时延保证。支持通过扩展字段传递 CubePod 超集参数。 |
Sandbox.create(...) [JS/TS] (v0.6.0 已验证) |
POST /sandboxesPOST /v2/sandboxes |
兼容 | pkg/gateway/sandboxes.go:handleCreateSandboxtest/e2b-compat-ts/src/e2b_compat.test.ts |
e2b@^2.64.0(@e2b/code-interpreter 暂未测) |
e2b npm 包的核心生命周期、commands.run、文件接口、getMetrics、Volumes、Secrets、网络规则与 Template 目录已由 make test-e2b-compat-ts 验证。 |
Sandbox.get_info(...) |
GET /sandboxes/{id} |
兼容 | pkg/gateway/sandboxes.go:handleGetSandboxtest/e2b-compat/test_official_e2b_extended.py |
e2b>=2.0.0 |
返回沙箱状态(running / paused)、资源规格与租约到期时间。 |
Sandbox.list() |
GET /v2/sandboxesGET /sandboxes |
兼容 | pkg/gateway/sandboxes.go:handleListSandboxesV2test/e2b-compat/test_official_e2b_extended.py |
e2b>=2.0.0 |
/v2/sandboxes 返回小写状态,兼容官方 Sandbox.list() 分页器。 |
sandbox.kill() / delete |
DELETE /sandboxes/{id} |
兼容 | pkg/gateway/sandboxes.go:handleDeleteSandboxtest/e2b-compat/test_official_e2b_sync.pytest/e2b-compat/test_official_e2b_async.py |
e2b>=2.0.0(依赖下限,非已测版本全集) |
释放计算 Pod。临时沙箱在销毁时自动回收临时存储;命名持久化工作区默认保留,除非显式指定删除。 |
sandbox.set_timeout(...) / 租约续期 |
POST /sandboxes/{id}/refreshesPOST /sandboxes/{id}/timeout |
兼容 | pkg/gateway/sandboxes.go:handleRefreshSandboxtest/e2b-compat/test_official_e2b_sync.pytest/e2b-compat/test_official_e2b_async.pypkg/gateway/e2b_conformance_test.go |
e2b>=2.0.0(依赖下限,非已测版本全集) |
续期沙箱租约并重置后台空闲回收计时。 |
Sandbox.connect(...) |
POST /v2/sandboxes/{id}/connectPOST /sandboxes/{id}/connect |
兼容 | pkg/gateway/sandboxes.go:handleConnectSandboxtest/e2b-compat/test_official_e2b_extended.py |
e2b>=2.0.0 |
重新连接运行中沙箱,或自动唤醒已暂停沙箱(但不保留暂停前的内存进程状态)。 |
sbx.get_metrics(...) / Sandbox.get_metrics(...) (v0.6.0 新增) |
GET /sandboxes/{sandboxID}/metricsGET /sandboxes/metrics |
部分兼容 | pkg/gateway/sandbox_metrics.gocrates/podd/src/metrics.rstest/e2b-compat/test_official_e2b_extended.pytest/e2b-compat-ts/src/e2b_compat.test.ts |
e2b>=2.0.0、e2b@^2.64.0、Go -race 与 Rust 单测 |
返回 SandboxMetric 快照(timestamp、timestampUnix、cpuCount、cpuUsedPct、memUsed、memTotal、memCache、diskUsed、diskTotal),支持 start/end 过滤(autoResume=false 时直接读取缓存而不唤醒暂停沙箱)。实例级 get_metrics / getMetrics 已在官方 Python 与 JS/TS CI 兼容套件中验证。 |
2. 命令与进程执行(Commands & Process Execution)
Section titled “2. 命令与进程执行(Commands & Process Execution)”| 官方 E2B 接口 | CubePod 网关路由 / 协议 | 状态 | 代码证据 / 实现指针 | 仓库测试声明 / 版本约束 | 行为差异与限制说明 |
|---|---|---|---|---|---|
sandbox.commands.run(...) (同步) |
POST /sandboxes/{id}/commandsPOST /sandboxes/{id}/commands/runConnect-RPC /process.Process/Start |
兼容 | pkg/gateway/commands.gopkg/gateway/connectrpc.gotest/e2b-compat/test_official_e2b_sync.pytest/e2b-compat/test_official_e2b_async.py |
e2b>=2.0.0(依赖下限,非已测版本全集) |
在 Guest 内通过 podd 以非特权 UID/GID 1000:1000(cubeplex)运行,工作目录默认为 /workspace。返回 stdout、stderr 与 exitCode。仅前台同步执行。 |
sandbox.commands.run(..., background=True) |
POST /sandboxes/{id}/commands(background: true)Connect-RPC /process.Process/Start |
兼容 | pkg/gateway/commands.gopkg/gateway/connectrpc.gotest/e2b-compat/test_official_e2b_extended.py |
e2b>=2.0.0 |
在 Guest 内创建后台进程组并返回含 pid 的句柄。 |
日志流式推送与回调(on_stdout、on_stderr) |
GET /sandboxes/{id}/commands/{cmdId}/logsGET /sandboxes/{id}/commands/{cmdId}/streamConnect-RPC /process.Process/Connect |
兼容 | pkg/gateway/commands.gopkg/gateway/connectrpc.gotest/e2b-compat/test_official_e2b_extended.py |
e2b>=2.0.0 |
实时将命令输出增量推送给 on_stdout / on_stderr 回调。 |
sandbox.commands.kill(pid) |
POST /sandboxes/{id}/commands/{cmdId}/killConnect-RPC /process.Process/SendSignal |
兼容 | pkg/gateway/commands.gopkg/gateway/connectrpc.gotest/e2b-compat/test_official_e2b_extended.py |
e2b>=2.0.0 |
终止后台进程组并在停止后返回 True。 |
sandbox.pty / 交互式伪终端 |
Connect-RPC /process.Process/*(pty: true):Start, Connect, SendInput,StreamInput, Update, SendSignal |
部分兼容 | pkg/gateway/connectrpc.gocrates/podd/src/commands.rstest/e2b-compat/test_official_e2b_extended.py |
e2b>=2.0.0 |
对用户的影响: 交互式 PTY 创建、标准输入、窗口大小调整(resize)、信号发送与 64 KiB 重连回放均可正常使用,但不支持半双工关闭标准输入(CloseStdin 返回 501 Not Implemented)。 |
3. 文件系统操作(Filesystem Operations)
Section titled “3. 文件系统操作(Filesystem Operations)”| 官方 E2B 接口 | CubePod 网关路由 / 协议 | 状态 | 代码证据 / 实现指针 | 仓库测试声明 / 版本约束 | 行为差异与限制说明 |
|---|---|---|---|---|---|
sandbox.files.write(path, data) |
PUT /sandboxes/{id}/filesPUT /filesConnect-RPC /filesystem.Filesystem/Write |
兼容 | pkg/gateway/files.gopkg/gateway/connectrpc.gotest/e2b-compat/test_official_e2b_sync.pytest/e2b-compat/test_official_e2b_async.pytest/e2b-compat/test_concurrent_sandboxes_isolation.py |
e2b>=2.0.0(依赖下限,非已测版本全集) |
写入文件时可创建父目录。pkg/gateway/files.go 中的路径检查会尝试拒绝包含 .. 的路径段;test/e2b-compat 覆盖的是向 /workspace 写入文本和二进制内容,并未枚举路径穿越用例。上传文件默认所有者为 1000:1000。 |
sandbox.files.read(path) |
GET /sandboxes/{id}/filesGET /filesConnect-RPC /filesystem.Filesystem/Read |
兼容 | pkg/gateway/files.gopkg/gateway/connectrpc.gotest/e2b-compat/test_official_e2b_sync.pytest/e2b-compat/test_official_e2b_async.pytest/e2b-compat/test_concurrent_sandboxes_isolation.py |
e2b>=2.0.0(依赖下限,非已测版本全集) |
从沙箱持久化 /workspace 或 RootFS 读取原始文件字节流(支持文本及 format="bytes" 二进制读取)。 |
sandbox.files.list(path) |
GET /sandboxes/{id}/files/listGET /files/listConnect-RPC /filesystem.Filesystem/*:List, ListDir |
兼容 | pkg/gateway/files.gopkg/gateway/connectrpc.gotest/e2b-compat/test_official_e2b_extended.py |
e2b>=2.0.0 |
返回目录条目列表及元数据(name、size、isDir、permissions)。 |
sandbox.files.remove(path) |
DELETE /sandboxes/{id}/filesDELETE /filesConnect-RPC /filesystem.Filesystem/Remove |
兼容 | pkg/gateway/files.gopkg/gateway/connectrpc.gotest/e2b-compat/test_official_e2b_extended.py |
e2b>=2.0.0 |
递归删除沙箱内的目标文件或目录。 |
sandbox.files.make_dir(path) |
Connect-RPC /filesystem.Filesystem/MakeDir |
兼容 | pkg/gateway/connectrpc.gotest/e2b-compat/test_official_e2b_extended.py |
e2b>=2.0.0 |
递归创建目录(权限 0755,默认归属 1000:1000)。 |
sandbox.files.watch_dir(path) |
Connect-RPC /filesystem.Filesystem/*:WatchDir, CreateWatcher,GetWatcherEvents, RemoveWatcher |
兼容 | pkg/gateway/watch.gopkg/gateway/connectrpc.gotest/e2b-compat/test_official_e2b_extended.py |
e2b>=2.0.0 |
实时监听目录创建/写入/删除事件并支持流式与轮询拉取。 |
4. 代码解释器(Code Interpreter, e2b-code-interpreter)
Section titled “4. 代码解释器(Code Interpreter, e2b-code-interpreter)”| 官方 E2B 接口 | CubePod 网关路由 / 协议 | 状态 | 代码证据 / 实现指针 | 仓库测试声明 / 版本约束 | 行为差异与限制说明 |
|---|---|---|---|---|---|
sandbox.run_code(code) [Python REPL] |
POST /sandboxes/{id}/code/executePOST /sandboxes/{id}/executePOST /execute |
兼容 | pkg/gateway/server.go:handleCodeExecutecrates/podd/src/interpreter.rstest/e2b-compat/test_official_code_interpreter.pytest/e2b-compat/test_multimodal_data_science.pytest/e2b-compat/test_streaming_realtime.pytest/e2b-compat/test_timeout_and_zombie_kill.py |
e2b-code-interpreter>=2.0.0(依赖下限,非已测版本全集) |
在 podd 内部执行 Python 代码,支持跨调用内存状态保持。流式输出 NDJSON 事件,包含 stdout、stderr、富文本/多模态结果(text、Base64 png 图表、html、json)及运行时错误调用栈。实时 on_stdout 分块流式回调由 test_streaming_realtime.py 验证,多模态输出由 test_multimodal_data_science.py 验证,超时强制终止由 test_timeout_and_zombie_kill.py 验证。 |
多语言执行内核(bash、js、ts、r、java) |
POST /sandboxes/{id}/code/execute |
部分兼容 | crates/podd/src/interpreter.rscrates/podd/src/tests.rs |
crates/podd 单元测试 |
沙箱内部 podd 守护进程原生支持 6 种有状态 REPL 内核。官方 Python e2b-code-interpreter SDK 测试主要覆盖 Python 环境。 |
上下文管理接口(/contexts) |
Guest 内部 podd(:49983) |
部分兼容 | crates/podd/src/main.rs:147crates/podd/src/tests.rs |
crates/podd 单元测试 |
Guest 内部 podd 支持 POST /contexts、GET /contexts、DELETE /contexts/{id} 与 POST /contexts/{id}/restart。协议差异:Gateway 未将 /sandboxes/{id}/code/contexts 暴露为顶层 REST 路由。客户端在 POST /sandboxes/{id}/code/execute 的请求体中通过 context_id 指定目标上下文,或直接向 podd 端口请求。 |
5. 模板目录与自定义构建(E2BTemplateAPI)
Section titled “5. 模板目录与自定义构建(E2BTemplateAPI)”| 官方 E2B 接口 | CubePod 网关路由 / 协议 | 状态 | 代码证据 / 实现指针 | 仓库测试声明 / 版本约束 | 行为差异与限制说明 |
|---|---|---|---|---|---|
Template.list() |
GET /templatesGET /v2/templates |
部分兼容 | pkg/gateway/templates.gotest/e2b-compat/test_official_e2b_extended.py |
e2b>=2.0.0 |
对用户的影响: 需要网关开启模板 API 开关,否则 GET /templates 返回旧版非标准格式。 |
Template.build(...) |
POST /templatesPOST /v2/templatesPOST /v3/templatesPOST /v2/templates/{id}/builds/{buildID} |
部分兼容 | pkg/gateway/templates.gopkg/controller/builder.gotest/e2b-compat/test_official_e2b_templates.py |
e2b>=2.0.0 |
对用户的影响: 需要开启模板构建开关(否则返回 501);构建产物不包含虚拟机内存快照(每次创建沙箱都会重新执行 startCmd),且任何针对 /workspace 的 COPY 或 WORKDIR 指令会被拒绝并返回 HTTP 400。 |
| 构建状态与日志查询 | GET /templates/{id}/builds/{buildID}/statusGET /templates/{id}/builds/{buildID}/logs |
兼容 | pkg/gateway/templates.gotest/e2b-compat/test_official_e2b_templates.py |
e2b>=2.0.0 |
返回构建状态(building、ready、error)与构建日志。 |
Template.exists(alias) / 模板别名与标签管理 |
GET /templates/aliases/{alias}GET /templates/{id}/tagsPOST /templates/tagsDELETE /templates/tags |
部分兼容 | pkg/gateway/templates.gotest/e2b-compat/test_official_e2b_templates.pytest/e2b-compat/test_official_e2b_extended.py |
e2b>=2.0.0 |
对用户的影响: 开启模板 API 后支持 Template.exists(alias) 及 assign_tags / get_tags / remove_tags;扩展标签查询子接口(/tags/count、/tags/exists、/tags/groups、/tags/tag-assignments)暂未实现。 |
6. 端口访问与子域名反向代理
Section titled “6. 端口访问与子域名反向代理”| 官方 E2B 接口 | CubePod 网关路由 / 协议 | 状态 | 代码证据 / 实现指针 | 仓库测试声明 / 版本约束 | 行为差异与限制说明 |
|---|---|---|---|---|---|
sandbox.get_host(port) |
GET /sandboxes/{id}/endpoints/{port} |
兼容 | pkg/gateway/server.go:handleGetEndpointtest/e2b-compat/test_official_e2b_extended.py |
e2b>=2.0.0 |
返回 <port>-<sandboxID>.<domain> 用于访问沙箱内暴露端口。 |
| 子域名 Ingress 路由 | Host: <port>-<sandboxID>.<domain> |
兼容 | pkg/gateway/server.go:hostRouterpkg/gateway/server_test.go |
Go 单元/集成测试 | 根据 <port>-<sandboxID>.<domain> 转发流量至对应沙箱端口,并在收到流量时自动唤醒已暂停沙箱。 |
7. 未测试或部分兼容生态边界
Section titled “7. 未测试或部分兼容生态边界”| 上游 E2B 生态组件 | 状态 | 对用户的影响与说明 |
|---|---|---|
官方 JS/TS SDK(e2b、@e2b/code-interpreter) |
部分兼容 | 对用户的影响: v0.6.0 变更。 上游 e2b npm 包(Sandbox.create、commands.run、getInfo、getMetrics、文件操作、pause/connect、Volumes、Secrets/Secret.fill、网络规则、Templates)已纳入 make test-e2b-compat-ts 持续验证;@e2b/code-interpreter 暂未覆盖。 |
| Agent 编排框架(LangChain、LlamaIndex、AutoGen、CrewAI、OpenHands、Smolagents) | 未测试 | 仓库内尚未集成针对各第三方框架的端到端测试套件。 |
官方 E2B Volumes API(POST /volumes、POST /volumes/rotate-key、/volumecontent/{id}/*、volumeMounts) |
部分兼容 | 对用户的影响: 卷管理与文件读写在 e2b>=2.0.0 下可用,但调用 vol.write_file() / vol.read_file() 连接自建网关时必须显式传入 api_url(否则上游 SDK 默认请求 e2b.app)。v0.8.0 变更: 在 Helm 中配置 volumes.rwxStorageClassName 后会自动激活共享 RWX PVC 并启用 Kubernetes 下的 K8sVolumeMounts(未配置时返回 501 Not Implemented)。v0.7.0 新增 / v0.8.0 更名: 支持卷内容令牌信封加密(CUBEPOD_VOLUMES_KEK / CUBEPOD_VOLUMES_KMS_URL)、租户 API Key 在线轮换(POST /volumes/rotate-key)、单租户存储字节配额(CUBEPOD_VOLUMES_MAX_TENANT_BYTES)及 RWX 容量监控告警(deploy/monitoring/volumes-alerts.yaml)。 |
官方 E2B Secrets API(POST /secrets、GET /secrets、POST /secrets/{id}、DELETE /secrets/{id}、Secret.fill()、network.rules) |
部分兼容 | 对用户的影响: Write-Only 密钥增删改查与 Secret.fill(name)(${e2b.secrets.<name>})已通过 test/e2b-compat/test_official_e2b_extended.py 中的 test_official_secret_crud_and_fill 验证,原生 Python/TS SDK 亦实现 Secret.fill / fillSecret 对齐。v0.6.0 变更: 新增 KubeSecretBackend(secrets.backend: "k8s")、后台同步及按需 Vault 重水合,支持多副本 Kubernetes 网关 HA 与严格 mTLS 交换。本地 Docker 模式仍不运行出站代理,因此出站头注入仅适用于 Kubernetes 模式。 |
沙箱生命周期事件与 Webhook(POST/GET /webhooks、PATCH/DELETE /webhooks/{id}、GET /events、GET /sandboxes/{id}/events) |
部分兼容 | 对用户的影响: v0.6.0 新增。 支持发送带 e2b-signature 签名的 E2B v1 生命周期事件(created、paused、resumed、updated、forked、killed),暂停/恢复模式为 pause_mode: "filesystem" 与 resume_mode: "reboot",并由 SyncPodBoxesOnce 异步捕获 K8s 空闲回收状态转换。在 v0.6.0 中,Webhook 配置与有界事件历史由内存维护并在配置了 CUBEPOD_EVENTS_DIR(或 CUBEPOD_STATE/Gateway 持久化 PVC)时持久化至本地磁盘;Kubernetes SandboxWebhook CRD + secretRef 多副本 HA 持久化计划在 v0.7.0 落地。 |
官方 E2B sandbox.git 助手 |
未测试 | 上游文档将 sandbox.git 说明为已弃用的 SDK 助手,它绑定在命令执行器上(Git 由 Commands 对象构造),并不是专用 HTTP Git 接口。test/e2b-compat 没有调用 sandbox.git。通过 sandbox.commands.run() 执行 git 只是普通 shell 命令路径,不能证明官方 git helper 兼容(例如 clone 选项、凭据助手、dangerously_authenticate、结构化 status/branch API 等)。 |
核心架构与行为语义差异
Section titled “核心架构与行为语义差异”1. 暂停与唤醒 vs. 内存快照
Section titled “1. 暂停与唤醒 vs. 内存快照”托管版 E2B 与 CubePod 在沙箱暂停与恢复的机制上存在根本性的架构语义差异:
- 上游 E2B Cloud:官方文档说明其暂停机制会同时保存文件系统状态与运行内存(RAM),在恢复时保留内存变量与运行中的后台守护进程。
- CubePod:采用云原生 Kubernetes 算力缩容至零(Scale-to-Zero)机制。调用暂停时(
POST /sandboxes/{id}/pause),计算 Pod 被终止销毁,但会保留rootfs与workspace两块 CSI 原始块持久卷:rootfs-pvc:挂载 OverlayFSupperdir,用于保存 RootFS 上的系统级修改与新装软件包。workspace-pvc:保存持久化的/workspace工作区。
- 唤醒时的核心语义差异(
connect或数据面流量到达):- CubePod 会启动新的计算 Pod,并重新挂载保留下来的
rootfs与workspace块卷。恢复耗时取决于部署与存储后端,本页不把它写成已测量的 SLA。 - 已落在这些持久卷上的文件系统变更在重新挂载后仍然可用;本页不承诺客户 Guest 内每一种状态都逐位一致。
- 仅存在于上一轮计算 Pod 中的内存和进程不会被恢复。若唤醒后仍需要守护进程,应写在模板
startCmd中,或由 Agent 再次启动。
- CubePod 会启动新的计算 Pod,并重新挂载保留下来的
2. 模板构建语义与 /workspace 拒绝机制
Section titled “2. 模板构建语义与 /workspace 拒绝机制”在 --e2b-template-api=true 下使用 Template.build() 时:
- CubePod 在 Kubernetes 中通过无特权 rootless BuildKit(或在本地模式下通过 Docker 守护进程)构建标准 OCI 容器镜像。
- 该过程不会生成处于暂停状态的虚拟机内存快照。
startCmd会在每个从该模板派生的新沙箱启动时重新执行。 - 核心安全与架构约束:Dockerfile 中任何针对
/workspace路径的COPY或WORKDIR指令均会被直接拒绝并返回 HTTP400 Bad Request(BuildException)。因为/workspace在沙箱运行时由独立的持久化块 PVC(workspace-pvc)动态挂载,若将文件固化在镜像的/workspace路径下,会被后续卷挂载完全遮盖。模板配方中的自定义文件请统一放置在/opt/、/usr/local/或其它系统路径下。
3. 代码解释器上下文管理路径(/contexts)
Section titled “3. 代码解释器上下文管理路径(/contexts)”在 E2B 规范中,代码解释器上下文可通过专门的上下文端点进行管理:
- 在 CubePod 中,支持 6 种语言(
python、bash、javascript、typescript、r、java)的状态化执行上下文由 Guest 内部的 Rustpodd守护进程(:49983)直接维护。 cubepod-gateway未将/sandboxes/{id}/code/contexts注册为公开 REST 路由。- 业务方在需要针对特定有状态上下文运行代码时,可直接在
POST /sandboxes/{id}/code/execute(或POST /sandboxes/{id}/execute)请求体的 JSON 中携带context_id。Gateway 会自动将上下文标识透传至podd。
4. 错误响应信封与异常映射
Section titled “4. 错误响应信封与异常映射”cubepod-gateway 内部不同子系统的错误响应信封格式略有不同:
- 模板 API 处理器(
pkg/gateway/templates.go):通过writeError返回标准 JSON 错误体:{"code": 404,"message": "template not found"} - Connect-RPC 处理器(
pkg/gateway/connectrpc.go):通过writeConnectError返回 Connect-RPC 格式的 JSON 错误体:{"code": "not_found","message": "sandbox not found"} - 核心 REST 沙箱处理器(
pkg/gateway/sandboxes.go):通过标准 Gohttp.Error返回纯文本错误体:sandbox not found
由于各子系统的错误信封格式存在差异,上游 SDK 在捕获特定错误类型(如特定 Python 异常类)时的映射行为可能与托管版 E2B 不完全一致。
CubePod 原生超集能力(扩展特性)
Section titled “CubePod 原生超集能力(扩展特性)”CubePod 提供了标准 E2B 协议所不具备的企业级高阶能力。这些特性可通过 CubePod 原生 SDK(sdks/python/、sdks/typescript/、Go 客户端 pkg/client 与 CLI cmd/cubepod)或 REST 超集端点调用:
- 持久化可写 RootFS 与无损系统重置:
调用
POST /sandboxes/{id}/reset-rootfs递增spec.rootfsGeneration,并分配新的 OSupperdirPVC。该操作不会替换沙箱的workspace-pvc。 - Copy-on-Write 沙箱分支克隆(CoW Fork):
调用
POST /sandboxes/{id}/fork通过FIFREEZE静默文件系统,在存储层对rootfs与workspace块卷做 CoW 克隆,再调用FITHAW解冻,从而得到独立的子沙箱。耗时取决于存储后端,本页不给出测量过的时延保证。 - 零信任出站凭据隔离(
cpodref_): 创建沙箱时传入secretBindings。沙箱内部只接触不透明占位符(如cpodref_openai_key),真实 API 密钥仅在流量通过cubepod-egress边车代理时在 mTLS 边界处动态替换。 - 流式工作区目录同步(
archive-sync): 调用POST /sandboxes/{id}/files/archive-sync将本地.tar/.tar.gz目录树以流式传输注入沙箱。pkg/gateway/files.go在解包时会检查并尝试拒绝包含..的路径段,本页不把它写成已经过完整审计的安全保证。该接口面向批量同步,而不是每个文件单独发一次 HTTP 请求。 - 按需桌面与签名面板代理:
调用
POST /sandboxes/{id}/desktop/start懒启动Xvfb、Chromium CDP、noVNC与ttyd,签发带 HMAC 签名的/panel/{token}/反向代理地址,用于实时可视化交互。
迁移指南与注意事项
Section titled “迁移指南与注意事项”从托管 E2B 迁移到私有化部署的 CubePod 时的检查清单:
- 确认环境变量配置:
在使用官方 SDK 前,确保已导出
E2B_DOMAIN(配合通配符 DNS)或同时导出了E2B_API_URL与E2B_SANDBOX_URL。 - 检查模板特性开关(
cmd/cubepod-gateway/main.go与cmd/cubepod-controller/main.go都定义了--e2b-template-api/--feature-gate=E2BTemplateAPI=true以及--template-build,但职责不同):- 在 cubepod-gateway 上开启
--e2b-template-api=true(或等价 feature gate),才会注册 E2B 模板 HTTP 路由。 - cubepod-gateway 也需要
--template-build=true,否则构建相关路由(上下文上传、日志、启动构建)会直接返回 HTTP 501,不会转到 Controller。 - 在 Kubernetes 中,真正执行 BuildKit 或 Docker 构建流水线的是 cubepod-controller,需要在 Controller 上开启
--template-build=true。Controller 也接受--e2b-template-api。 - 在本地单进程模式(没有 Kubernetes 客户端,也没有
--controller-url)下,由 Gateway 进程内的 reconciler 使用LocalDockerBuilder,不必单独再跑一个 Controller。
- 在 cubepod-gateway 上开启
- 排查模板中的
/workspace路径: 检查用于构建模板的 Dockerfile,确保未包含针对/workspace的COPY指令。 - 适配进程生命周期:
注意后台内存常驻进程不会在暂停期间被持久化,关键业务数据请统一落盘至
/workspace或系统目录。 - 本地运行兼容性验证套件:
维护人员可通过以下命令验证网关的 Python SDK 协议兼容性:
Terminal window make test-e2b-compat
- 在 API 概览与流式协议 中查阅完整的 REST 与流式协议规范。
- 打开 交互式 OpenAPI 控制台 进行在线接口调试。
- 查阅原生多语言客户端指南:Python SDK 与 TypeScript SDK。
- 参考 Kubernetes 与 Helm 生产部署 配置 Kata 容器与块存储存储类。