@agentproto/sandbox-e2b

中文文档
0.11.2发布于 2026/11/06Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 5539

@agentproto/sandbox-e2b — e2b SandboxProvider for @agentproto/sandbox. Boots the pinned agentproto-workstation e2b template (baked @agentproto/cli 1.31.0), starts the agentproto daemon inside it, and exposes its MCP endpoint as a URL so any AgentSessi

原始使用文档
文档目录7 节
  1. Usage
  2. Sizes
  3. Build environment
  4. Pushing and opening PRs from the box
  5. Port exposure
  6. Notes
  7. License

@agentproto/sandbox-e2b

e2b SandboxProvider for @agentproto/sandbox. Boots the pre-built agentproto-workstation e2b template, starts the agentproto daemon inside it, and exposes its MCP endpoint as a URL — so createSandboxAgentSessionHost can hand it straight to connectDaemonAgentSessionHost (@agentproto/worktree) and run any AgentStep inside the sandbox, unchanged.

Usage

import { createSandboxAgentSessionHost } from "@agentproto/sandbox"
import { e2bSandboxProvider } from "@agentproto/sandbox-e2b"
import { runWorkflow } from "@agentproto/workflow-runtime"
import { worktreeAgentWorkflow } from "@agentproto/worktree"

const host = await createSandboxAgentSessionHost({
  provider: e2bSandboxProvider,
  spec: { provider: "e2b", config: {} },
  secrets: { slugs: ["OPENROUTER_API_KEY"] },
})
try {
  await runWorkflow({ workflow: worktreeAgentWorkflow, input, agents: host })
} finally {
  await host.stop()
}

Requires E2B_API_KEY in the host process's environment.

Sizes

Pick the box size per spawn with config.size. Each size is its own published template (agentproto-workstation-<size>, declared in templates/workstation/versions.json):

agent_start({ sandbox: { provider: "e2b", config: { size: "large" } } })
sizevCPURAM (MB)e2b aliasstatus
nano11024agentproto-workstation-nanopublished
small22048agentproto-workstation-smallpublished
medium24096agentproto-workstation-mediumpublished
large (default)48192agentproto-workstation-largepublished
x-large816384agentproto-workstation-x-largeunavailable — e2b refused: 400: Memory can't be higher than 8192 MiB (if you need to increase this limit, please contact support)
xx-large1632768agentproto-workstation-xx-largeunavailable — e2b refused: 400: CPU count can't be higher than 8 (if you need to increase this limit, please contact support)

The bare agentproto-workstation alias (and agentproto-workstation-dev) is built at the default size, large (4 vCPU / 8192 MB).

  • A full pnpm build + pnpm test of agentproto/ts needs large or bigger. Smaller boxes OOM-kill the session mid-build and the work is lost with the box.
  • No size and no template boots the bare agentproto-workstation template, which is built at the default size. An explicit config.template always wins over config.size.
  • An unknown size fails the boot with the list of valid ones. A size marked unavailable fails with the exact error e2b returned when its template was refused (today: the plan caps a sandbox at 8 vCPU / 8192 MB), rather than booting a smaller box.
  • e2b has no GPU sandboxes, so there is no GPU size.

Build environment

Next to the 4 GiB swap file it enables on a fresh boot, the provider sizes Node builds to the box: pnpm runs one package build per vCPU by default and each tsup DTS worker takes Node's default heap, so a plain pnpm build dies with JavaScript heap out of memory long before the RAM is gone. On every boot it derives a budget from the resolved size preset — concurrency = max(1, min(cpu, floor(ram MB / 3072))) and heap = clamp(floor(ram MB * 0.6 / concurrency), 768, 4096) (the default 4 vCPU / 8192 MB box → 2 builds at a 2457 MB heap) — and ships it as NODE_OPTIONS=--max-old-space-size=…, npm_config_workspace_concurrency and TURBO_CONCURRENCY two ways: in the daemon's start env, so the daemon and every adapter it spawns inherit them, and in /etc/profile.d/agentproto-build.sh, so every login-shell command in the box (the agent's bash tool, any exec) sources them too. An explicit config.template has no recorded size, so the box is probed once at boot (nproc, free -m). A caller's own value always wins: a passed NODE_OPTIONS with --max-old-space-size is kept untouched, one without gets the box heap appended. Override the numbers with config.buildEnv: { concurrency, heapMb }, or disable the whole thing with config.buildEnv: false.

Pushing and opening PRs from the box

The workstation template bakes the GitHub CLI (gh, pinned in templates/workstation/versions.json → tools.gh). When the spawn's workspace has a registered remote (agentproto workspace remote set <slug> --url <https-url> --token-stdin), the daemon injects that token into the box twice: as AGENTPROTO_GIT_TOKEN, read by the git credential helper, and as GH_TOKEN, read by gh. So the agent can git push and gh pr create itself, provided the token has Contents: write and Pull requests: write on the repository (a fine-grained PAT scoped to that one repo is the right shape).

Both names are reserved. They are only ever derived by the daemon from the workspace's own keychain ref, and they are stripped from any caller-declared env.passthrough, env.auth.state.env or join.tokenEnv. So a caller can neither shadow the token nor pull the daemon's own GH_TOKEN into a box. The token never appears in a command, URL or argv. It is still an ordinary env var inside the box, so the agent can read it: scope it to the one repository and revoke it when the work is done.

Port exposure

Each booted sandbox exposes an expose(port) method that returns the public URL for any port the sandboxed process listens on:

const host = await createSandboxAgentSessionHost({ provider: e2bSandboxProvider, spec, secrets })
// After booting, expose any app port the sandboxed process is listening on:
const { url } = await host.expose!(3210)
// url → "https://3210-<sandboxId>.e2b.app"

To pre-expose ports at boot time, declare extraPorts in the spec. The returned BootedSandbox.ports map (and the session descriptor's sandboxPorts field) are populated immediately so orchestrators can read the URL without a separate expose() call:

const host = await createSandboxAgentSessionHost({
  provider: e2bSandboxProvider,
  spec: { provider: "e2b", config: {}, extraPorts: [3210] },
  secrets: { slugs: ["E2B_API_KEY"] },
})
console.log(host.ports) // { 3210: "https://3210-<sandboxId>.e2b.app" }

Loopback bind is enough inside the VM — e2b's edge handles forwarding. See SandboxPortExposureUnsupportedError in @agentproto/sandbox for the error thrown when calling exposePort() on a provider that does not support exposure.

Notes

  • The daemon's own origin allowlist defaults to localhost:*; this provider opens it for the sandbox's own public host (--allow-origin https://<getHost>) so the host process can reach it over https://<getHost>/mcp.
  • Custom (non-baked) templates can lag behind: the provider runs npm i -g @agentproto/cli@<cliVersion> before starting the daemon on them (cliVersion defaults to @latest; pin it in spec.config for reproducible boots). Set updateCliOnBoot: false in spec.config to skip the install entirely.

License

MIT — see LICENSE.

版本与发布记录

@agentproto/sandbox-e2b 共发布 45 个版本,首次发布于 2026/07/08;过去 12 个月发布了 45 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.11.2latest2026/11/06今天
0.11.12026/11/042 天前
0.11.02026/11/014 天前
0.10.02026/10/279 天前
0.9.12026/10/2314 天前
0.9.02026/10/2017 天前

关于 @agentproto/sandbox-e2b 的常见问题

@agentproto/sandbox-e2b 是什么?

@agentproto/sandbox-e2b — e2b SandboxProvider for @agentproto/sandbox. Boots the pinned agentproto-workstation e2b template (baked @agentproto/cli 1.31.0), starts the agentproto daemon inside it, and exposes its MCP endpoint as a URL so any AgentSessi

如何安装 @agentproto/sandbox-e2b?

在项目目录运行 npm install @agentproto/sandbox-e2b,或使用 pnpm add / yarn add / bun add。

@agentproto/sandbox-e2b 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@agentproto/sandbox-e2b 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@agentproto/sandbox-e2b 可以商用吗?

@agentproto/sandbox-e2b 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@agentproto/sandbox-e2b 的下载量有多少?

根据 npm 官方下载统计,@agentproto/sandbox-e2b 在 2026/10/05 – 2026/11/03 这 30 天内被下载 5,539 次,日均约 185 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@agentproto/sandbox-e2b 还在维护吗?

最新版本 0.11.2 发布于 2026/11/06(今天);至今共发布 45 个版本,其中过去 12 个月发布了 45 个;首次发布于 2026/07/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。