E2B 沙箱运行时
E2B:在隔离 micro-VM 里执行 AI 生成代码的云端 runtime。Python / TS SDK 通过 Connect-RPC 调用 envd 守护进程(Rust + protobuf)。
晶体简介
Constraints
Evidence Quality
High confidence — strong evidence base
3 条不可违反的约束
WHENWriting TypeScript SDK code that calls Sandbox (any e2b npm package consumer scenario).
ACTIONWrap each Sandbox.create() in try/finally and `await sandbox.kill()` in the finally block — the TS Sandbox class does NOT implement Symbol.dispose / Symbol.asyncDispose, so a `using` block does not auto-cleanup.
CONSEQUENCEIf a TS caller misses `await sandbox.kill()`, the sandbox keeps billing until the 5-minute default timeout reclaims it server-side; every leak adds up to 5 minutes of billable time, and long loops or exception paths multiply cost.
WHENImplementing a stateful agent loop that needs to retain in-sandbox filesystem/process/RAM state across multiple conversation turns.
ACTIONPass lifecycle={'on_timeout': 'pause', 'auto_resume': True} explicitly to Sandbox.create() — omitting it equals auto_pause=False (hard-coded at main.py:219), and on timeout the sandbox is KILLED and all state is lost.
CONSEQUENCEWithout a lifecycle config, the sandbox is destroyed at timeout, all filesystem/process/RAM state is lost, the next connect() hits a deleted sandbox raising SandboxNotFoundException, and the agent's multi-turn context chain breaks.
WHENPlanning the maximum duration of a single sandbox task / picking an E2B tier.
ACTIONDo NOT let a single Sandbox task run beyond the tier cap — Hobby tier hard cap is 1h, Pro tier is 24h, enforced server-side; the platform KILLs the sandbox regardless of any timeout the SDK passes.
CONSEQUENCEExceeding 1h on Hobby kills the task at 1h and loses all in-memory state; if the caller has no progress checkpoint, the entire task rolls back. The same applies to 24h on Pro.
常见问题
讨论 (0)
暂无讨论,成为第一个发言的人吧!
更新历史
v0.1.0: 首次发布到 Doramagic.ai。基于 e2b-dev/E2B 的 AI 代码沙箱 runtime,中英双语 + 42 条 anti-pattern 约束(3 条 fatal)+ 3 条 FAQ。
v0.1.0: 首次发布到 Doramagic.ai。基于 e2b-dev/E2B 的 AI 代码沙箱 runtime,中英双语 + 42 条 anti-pattern 约束(3 条 fatal)+ 3 条 FAQ。