E2B 沙箱运行时

E2B:在隔离 micro-VM 里执行 AI 生成代码的云端 runtime。Python / TS SDK 通过 Connect-RPC 调用 envd 守护进程(Rust + protobuf)。

✓ 0 人报告成功·v0.1.0·

晶体简介

E2B 是在隔离 micro-VM 里执行 AI 生成代码的云端 runtime(github.com/e2b-dev/E2B)。Python / TypeScript SDK 是纯 RPC 客户端,通过 Connect-RPC 对接 envd 守护进程(Rust + protobuf,托管在独立的 e2b-dev/infra repo)。 SDK 接口为 2x2:{Sandbox, AsyncSandbox} × {Template, AsyncTemplate}。Sandbox / AsyncSandbox 各带四个子模块作为实例属性:files: Filesystem / commands: Commands / pty: Pty / git: Git。多态在 gRPC .proto schema(process_pb2 / filesystem_pb2)里,不在 Python @abstractmethod。 本 skill 自带 42 条约束(含 3 条 fatal),覆盖典型踩坑:TS 用户忘记 kill()——TS Sandbox 没有 Symbol.dispose 也没有自动清理;通过 envs={...} 传 API key 会被 commands.list() 泄露给持有 sandbox 句柄的人;三个看着像但其实不一样的 timeout(files.write() 默认 60s 静默杀掉大文件上传)。

Blueprint Source

finance-bp-141

e2b-dev/E2B557b7231 source file

Constraints

3total
3fatal
3 must-not-violate

Evidence Quality

Confidence90%

High confidence — strong evidence base

3 条不可违反的约束

FATALdomain_rulee2b-C-001

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.

FATALdomain_rulee2b-C-004

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.

FATALdomain_rulee2b-C-026

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.02026-04-25·贡献者: tangweigang-jpg

v0.1.0: 首次发布到 Doramagic.ai。基于 e2b-dev/E2B 的 AI 代码沙箱 runtime,中英双语 + 42 条 anti-pattern 约束(3 条 fatal)+ 3 条 FAQ。

v0.1.02026-04-25·贡献者: tangweigang-jpg

v0.1.0: 首次发布到 Doramagic.ai。基于 e2b-dev/E2B 的 AI 代码沙箱 runtime,中英双语 + 42 条 anti-pattern 约束(3 条 fatal)+ 3 条 FAQ。