Anthropic开源sandbox-runtime实现AI Agent沙箱隔离
Meet Anthropic’s sandbox-runtime: OS-Level Sandboxing for AI Agents, No Containers
Agent安全是落地关键痛点,这个无容器沙箱方案提供了具体的工程实现路径和配置示例,值得做Agent开发的同学参考集成。
In this article, we will discuss newly trending open sourced Anthropic’s sandbox-runtime (srt), the OS-level sandbox behind Claude Code’s sandboxed bash tool. The Anthropic sandbox-runtime limits which files a process can touch and which hosts it can reach. It does this without spinning up a container. It is also not tied to Claude Code. Your own agents, local MCP servers and plain command-line programs can run inside it.
在本文中,我们将讨论 Anthropic 新推出的开源沙箱运行时(sandbox-runtime,简称 srt),这是 Claude Code 的沙箱化 bash 工具背后的操作系统级沙箱。Anthropic sandbox-runtime 限制了进程可以访问的文件以及可以连接的主机。它无需启动容器即可实现这一功能。它也不局限于 Claude Code。你自己的代理、本地 MCP 服务器和普通的命令行程序都可以在其中运行。
TL;DR
TL;DR(太长不看)
- Size: npm package @anthropic-ai/sandbox-runtime v0.0.81, about 11.4 MB unpacked, Apache-2.0, Node.js 22.12+.
- Runs on: any macOS or Linux dev machine or CI box. macOS uses Seatbelt; Linux needs bubblewrap, socat and ripgrep. Windows is alpha.
- Performance: sandboxing cut Claude Code permission prompts by 84% in Anthropic’s internal usage (self-reported).
- Best: 84% fewer permission prompts, with file and network limits enforced on the whole process tree.
- Worst: still a beta research preview, Windows support is alpha.
- 大小:npm 包 @anthropic-ai/sandbox-runtime v0.0.81,解压后约 11.4 MB,采用 Apache-2.0 许可证,需要 Node.js 22.12+。
- 运行环境:任何 macOS 或 Linux 开发机或 CI 服务器。macOS 使用 Seatbelt;Linux 需要 bubblewrap、socat 和 ripgrep。Windows 处于 Alpha 阶段。
- 性能:在 Anthropic 的内部使用中,沙箱化使 Claude Code 的权限提示减少了 84%(自我报告数据)。
- 优点:权限提示减少 84%,并对整个进程树强制执行文件和网络限制。
- 缺点:仍处于 Beta 研究预览阶段,Windows 支持为 Alpha 版本。
What is Anthropic sandbox-runtime?
什么是 Anthropic sandbox-runtime?
Anthropic sandbox-runtime is an open-source tool that wraps any process in filesystem and network restrictions. You install it with npm install -g @anthropic-ai/sandbox-runtime, then prefix a command with srt. It works as a CLI and as a TypeScript library.
Anthropic sandbox-runtime 是一个开源工具,可将任何进程包裹在文件系统和网络限制中。你可以通过 npm install -g @anthropic-ai/sandbox-runtime 安装它,然后在命令前加上 srt 前缀。它既可作为 CLI 使用,也可作为 TypeScript 库使用。
How does sandbox-runtime work on macOS, Linux and Windows?
sandbox-runtime 如何在 macOS、Linux 和 Windows 上工作?
srt uses each operating system’s own isolation primitives. Its restrictions cover the entire process tree, including scripts and subprocesses.
srt 使用每个操作系统的原生隔离原语。其限制覆盖整个进程树,包括脚本和子进程。
- macOS: sandbox-exec with dynamically generated Seatbelt profiles. Only ripgrep is required.
- Linux: bubblewrap with the network namespace removed. It also needs socat and ripgrep.
- Windows (alpha): a dedicated srt-sandbox account, a Windows Filtering Platform egress fence and explicit file ACLs.
- macOS:使用动态生成的 Seatbelt 配置文件进行 sandbox-exec。仅需 ripgrep。
- Linux:使用移除网络命名空间的 bubblewrap。还需要 socat 和 ripgrep。
- Windows(Alpha 阶段):专用的 srt-sandbox 账户、Windows Filtering Platform 出站防火墙以及显式的文件 ACL。
Traffic leaves only through HTTP and SOCKS5 proxies running on the host. On Linux, those proxies sit behind Unix sockets bind-mounted into the sandbox. On macOS, the Seatbelt profile allows only one localhost port. The proxies then apply your domain allowlist and denylist.
流量仅通过主机上运行的 HTTP 和 SOCKS5 代理离开。在 Linux 上,这些代理位于 Unix 套接字后面,并挂载到沙箱中。在 macOS 上,Seatbelt 配置文件仅允许一个 localhost 端口。然后,代理会应用你的域名白名单和黑名单。
Why does it need both filesystem and network isolation?
为什么它需要同时具备文件系统和网络隔离?
Anthropic team argues that 1 boundary without the other fails. Without network isolation, a prompt-injected agent could exfiltrate SSH keys. Without filesystem isolation, it could escape the sandbox and gain network access.
Anthropic 团队认为,缺少另一方的单一边界是无效的。如果没有网络隔离,遭受提示注入的代理可能会窃取 SSH 密钥。如果没有文件系统隔离,它可能会逃逸出沙箱并获得网络访问权限。
srt’s defaults follow that logic. Reads are allowed everywhere unless denied. Writes are denied everywhere unless allowed. Network access is denied unless a domain is allowlisted.
srt 的默认设置遵循这一逻辑。除非被拒绝,否则允许所有读取操作。除非被允许,否则拒绝所有写入操作。除非域名在白名单中,否则拒绝网络访问。
How do you sandbox an MCP server or your own agent?
如何对 MCP 服务器或你自己的代理进行沙箱隔离?
For an MCP server, change the command in .mcp.json from npx to srt. Pass the original command as arguments. Rules then live in ~/.srt-settings.json:
对于 MCP 服务器,将 .mcp.json 中的命令从 npx 更改为 srt。将原始命令作为参数传递。规则随后存储在 ~/.srt-settings.json 中:
{
"network": { "allowedDomains": ["api.github.com", "*.npmjs.org"], "deniedDomains": [] },
"filesystem": { "denyRead": ["~/.ssh"], "allowWrite": ["."], "denyWrite": [".env"] }
}For your own agent, the library exposes SandboxManager. Call initialize(config) to start the proxies. Then wrapWithSandbox() returns a wrapped command string you can spawn.
对于你自己的代理,该库提供了 SandboxManager。调用 initialize(config) 启动代理。然后 wrapWithSandbox() 返回一个你可以用于生成进程的包装后的命令字符串。
What does the 84% figure mean?
84% 这个数字意味着什么?
Anthropic reports that sandboxing reduced permission prompts by 84% in internal Claude Code usage. That is a self-reported number, not an external benchmark. The target is approval fatigue. Developers who click “approve” all day stop reading what they approve. A fixed boundary lets the agent work freely inside it and ask only at the edge.
Anthropic 报告称,在内部 Claude Code 使用中,沙箱化使权限提示减少了 84%。这是一个自我报告的数字,而非外部基准测试。其目标是解决“批准疲劳”问题。整天点击“批准”的开发者会停止阅读他们批准的内容。固定的边界让代理在其中自由工作,仅在边缘处发起询问。
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力