跳到主内容
@wquguru
精选88r/LLMDevs(Reddit)技巧与观点

Claude Code 沙箱默认关闭,Agent 安全配置实操指南

Everyone says "sandbox your agent." Claude Code's sandbox is off by default

原文
发到 X
推荐理由

Agent 落地必看的硬核安全配置清单,涵盖 Claude Code、Docker 及云原生环境的避坑细节,直接可复用。

The Qwen3.8-Flash-Next threads keep ending on "sandbox your agent," and a top reply asked how. Nobody posted settings, so we read the docs for the tools most of you run. Commands are on the card.

Qwen3.8-Flash-Next 的讨论帖总是以“沙盒化你的代理”结尾,而一条高赞回复询问了具体做法。没有人发布设置方法,所以我们查阅了你们大多数人使用的工具的文档。相关命令已列在卡片上。

Claude Code ships with the sandbox off. Turn it on with /sandbox or sandbox.enabled. Network then goes through a local proxy whose domain allowlist starts empty. Set sandbox.failIfUnavailable to true. Without it, a sandbox that can't start (on Linux it needs bubblewrap and socat) means your commands run unsandboxed. Native Windows has no sandbox, so use WSL2.

Claude Code 默认关闭沙盒功能。通过 /sandbox 或 sandbox.enabled 开启它。网络流量随后会通过一个本地代理,其域名白名单初始为空。将 sandbox.failIfUnavailable 设置为 true。如果不这样做,无法启动的沙盒(在 Linux 上需要 bubblewrap 和 socat)意味着你的命令将在无沙盒环境下运行。原生 Windows 没有沙盒支持,因此请使用 WSL2。

Codex CLI keeps network off in workspace-write mode unless you enable it. Grep your config.toml for network_access = true before counting on that.

Codex CLI 在 workspace-write 模式下默认保持网络关闭,除非你启用它。在依赖该功能之前,请在 config.toml 中搜索 network_access = true。

For jobs with no network needs, like tests, docker run --network none gives the container loopback only. For a full coding agent, Docker Sandboxes (sbx) puts it in a microVM with its own network policy. We'd start at deny-all and add hosts one by one.

对于没有网络需求的工作负载(如测试),docker run --network none 仅给容器提供回环接口。对于完整的编码代理,Docker Sandboxes (sbx) 将其置于具有独立网络策略的微虚拟机中。我们建议从拒绝所有流量开始,然后逐个添加主机。

Need some web? Send egress through an allowlist proxy. Stripe's Smokescreen allows by hostname and refuses internal IPs.

如果需要访问网页?通过允许列表代理发送出站流量。Stripe 的 Smokescreen 允许基于主机名访问,并拒绝内部 IP。

On a cloud VM, the metadata endpoint at 169.254.169.254 can hand out the VM's role credentials. On AWS, require IMDSv2 and drop that address for agent containers (DOCKER-USER rule on the card).

在云 VM 上,位于 169.254.169.254 的元数据端点可以分发 VM 的角色凭证。在 AWS 上,要求使用 IMDSv2 并为代理容器丢弃该地址(卡片上的 DOCKER-USER 规则)。

Cohere's write-up also had the model use unshare to get root in its own namespace. Ubuntu 24.04 restricts unprivileged user namespaces by default. Docker's default seccomp profile blocks unshare unless the container gets CAP_SYS_ADMIN or runs with seccomp=unconfined.

Cohere 的文章还提到模型使用 unshare 在其自己的命名空间中获取 root 权限。Ubuntu 24.04 默认限制非特权用户命名空间。Docker 的默认 seccomp 配置文件会阻止 unshare,除非容器获得 CAP_SYS_ADMIN 权限或以 seccomp=unconfined 运行。

The pushback in those threads: lock it down this hard and the agent is useless. Where do you land? Network off with a per-task allowlist, or full access inside a throwaway VM?

这些讨论中的反对意见是:如果锁定得如此严格,代理就毫无用处。你会选择哪种方案?是关闭网络并使用按任务配置的允许列表,还是在一次性 VM 内给予完全访问权限?

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件