@agentproto/sandbox

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

@agentproto/sandbox — AIP-36 SANDBOX.md reference implementation. A composable schema block defining the sandbox field — provider, config, command env, network egress, resource limits — for any manifest that names a compute environment for agent-issued

原始使用文档
文档目录7 节
  1. Usage
  2. Running an agent step inside a sandbox
  3. Adapter auto-install on boot
  4. Billing-auth auto-passthrough (opt-in)
  5. Lifetime: re-armed while the session works
  6. Lifecycle: pause is the default teardown
  7. License

@agentproto/sandbox

AIP-36 SANDBOX.md reference implementation. A composable schema block defining the sandbox field — provider, config, command env, network egress, resource limits — for any manifest that names a compute environment for agent-issued shell commands. Sibling primitive to STORAGE.md (AIP-35); inline or ref, mirroring AIP-17 RUNNER and AIP-19 SECRETS.

Status: 0.1.0-alpha. Generated by scripts/scaffold-aip.mjs — build() and validate() bodies are TODOs.

Spec: https://agentproto.sh/docs/aip-36

Usage

import { defineSandbox } from "@agentproto/sandbox"

const x = defineSandbox({
  id: "my-sandbox",
  description: "Short purpose.",
  // ...
})

Running an agent step inside a sandbox

createSandboxAgentSessionHost turns any SandboxProvider into an AgentSessionHost (@agentproto/workflow-runtime) — the seam runWorkflow injects for every AgentStep. It resolves the requested secrets into an env map, boots the sandbox with that env, then connects connectDaemonAgentSessionHost (@agentproto/worktree) to the sandbox's exposed agentproto daemon — reusing the same daemon-backed session host a local run would use, unchanged.

import { createSandboxAgentSessionHost } from "@agentproto/sandbox"
import { e2bSandboxProvider } from "@agentproto/sandbox-e2b"

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

Adapter auto-install on boot

A box's boot-time npm i -g @agentproto/cli replaces the global install and loses the template-baked @agentproto/adapter-* packages. Providers that accept config.installPackages (e2b, box) install those entries in the SAME npm invocation as the CLI update; when spawning through the runtime (spawnAgentSession), the adapter about to be launched — plus @anthropic-ai/claude-code for the claude-code adapter — is injected there automatically (a caller-declared pin always wins, nothing is injected for non-sandbox spawns).

For harnesses BEYOND the spawned adapter, declare semantic slugs instead of raw npm specs: config.installAdapters: ["hermes", "claude-code"]. Each slug expands to @agentproto/adapter-<slug>@latest (plus that adapter's declared boot extras, e.g. @anthropic-ai/claude-code) and merges into config.installPackages with dedupe — a caller's explicit pin for the same package always wins. An unknown slug still expands (the box's npm install is the authority); an absent field changes nothing.

Billing-auth auto-passthrough (opt-in)

Set env.autoPassthrough: true on a sandbox spec and the runtime adds the spawn's RESOLVED billing-credential env-var NAME (e.g. ANTHROPIC_API_KEY) to env.passthrough before the box boots — so a fresh box inherits host auth without the caller naming vars. Only the NAME is injected; the value travels via the normal passthrough mechanism (host secrets broker → box env) and is never read by the flag. Billing credential only (no GITHUB_TOKEN); the caller's explicit env.passthrough entries are kept and deduped. When no credential resolved — or the host cannot resolve the var — nothing is injected and the spawn proceeds: the flag is a convenience, not a contract.

Lifetime: re-armed while the session works

A provider box has a lifetime (e2b: timeoutMs, 45 min by default, 1 h account cap). It counts from the last re-arm, not from boot. While its session is active the runtime keeps re-arming it with the same duration: on each prompt dispatch, on streamed box events (at most once a minute), and every 10 minutes while a turn is in flight, even one that streams nothing for a long time (a single long tool call). An idle box is not renewed and expires on schedule.

About 5 minutes before the deadline it knows about, the proxy acts once more. If a turn is still in flight it tries one last renewal. If the session is idle, or that renewal fails, it runs a final checkpoint while the box's filesystem can still be reached. A detached box (host-daemon restart) follows its own rule: it is asked for 1 h from the moment of detach.

Lifecycle: pause is the default teardown

Closing a session PAUSES its box by default (pause({ keepMemory: true })) rather than killing it — any closed box stays reattachable via sandbox.reuse / agentproto sandbox attach. A paused box still dies at its own timeoutMs (45 min by default), so paused boxes don't accumulate indefinitely; declare lifecycle.destroy_on for a hard kill on close.

License

MIT — see LICENSE.

版本与发布记录

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

版本发布日期距今
0.16.0latest2026/11/042 天前
0.15.02026/11/014 天前
0.14.02026/10/279 天前
0.13.02026/10/2314 天前
0.12.22026/10/2017 天前
0.12.12026/10/1917 天前

关于 @agentproto/sandbox 的常见问题

@agentproto/sandbox 是什么?

@agentproto/sandbox — AIP-36 SANDBOX.md reference implementation. A composable schema block defining the sandbox field — provider, config, command env, network egress, resource limits — for any manifest that names a compute environment for agent-issued

如何安装 @agentproto/sandbox?

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

@agentproto/sandbox 支持 TypeScript 吗?

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

@agentproto/sandbox 支持 ESM 还是 CommonJS?

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

@agentproto/sandbox 可以商用吗?

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

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

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

@agentproto/sandbox 还在维护吗?

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