如何在沙箱环境中允许Codex CLI执行能够访问互联网的shell命令?

人工智能 2026-07-07

例如,我希望Codex能执行如下命令:

curl https://github.com

我可以用简单的方式测试这个:

codex exec 'Can you "curl https://github.com" through sandbox?'

在默认的 config.toml 下会失败,输出为:

No. From the shell sandbox, `curl -I https://github.com` failed:

``text
curl: (7) CONNECT tunnel failed, response 403
HTTP/1.1 403 Forbidden
x-proxy-error: blocked-by-allowlist
``

So outbound network from the sandbox is being blocked by the proxy allowlist for `github.com`.

但我想保留沙箱,也就是说我想保留我的:

sandbox_mode = "workspace-write"

并且不必执行以下操作:

sandbox_mode = "danger-full-access"

我理解互联网访问会增加秘密外泄的风险,但我计划通过其他手段进一步加以控制。

解决方案

截至codex-cli 0.142.3、Ubuntu 26.04的测试结果,在 .codex/config.toml 上可行:

sandbox_mode = "workspace-write"

[sandbox_workspace_write]
network_access = true

如果你正在使用自定义的 default_permissions,语法如下:

sandbox_mode = "workspace-write"
default_permissions = "workspace_custom"

[permissions.workspace_custom]
description = "Workspace sandbox with further restrictions."
extends = ":workspace"

[permissions.workspace_custom.network]
enabled = true

如果你想仅允许访问某些网站以降低秘密外泄风险,可以添加:

[features.network_proxy]
enabled = true

[features.network_proxy.domains]
"api.openai.com" = "allow"
"docs.python.org" = "allow"
"**.github.com" = "allow"
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章