CLOSEAI的codex左右脑互博设定之win上的approval_policy和sandbox_mode

作为win用户刚开始使用codex的时候真的太折磨了。试想一下,你等着codex慢的要死的high响应,然后它每次查看文件都请求你同意一次,几分钟来一次…

太折磨了!

于是受不了的我,开始尝试配置sandbox_modeapproval_policy

然后 更迷惑了!

怎么配了sandbox_mode = "workspace-write"还是不行啊?

怎么配了approval_policy = "on-failure"还是不行啊?

怎么配了approval_policy = "never"还是不行啊?

最后配置了 sandbox_mode = "danger-full-access" 才终于不再请求了。

好了,本文完结。

如果你想知道原因,可以继续往下看。

毕竟这行为和配置描述不一样啊,而且这样配置会不会有安全隐患啊?

于是我开始实验

环境

  • 配置$env:CODEX_HOME防止破环本地codex环境
  • AGENTS.md添加禁止包裹执行 防止白名单命令识别错误 原因看我另一篇帖子

默认情况

approval_policy = "on-request"
sandbox_mode = "read-only"

结果

  • 包裹执行
    • 执行ls → 请求授权
  • 禁止包裹执行
    • 执行ls → 直接执行并被识别
    • 执行非白名单命令 → 请求授权

这个看起来就很符合直觉,所以包裹执行肯定是不行的,所以后续只测试禁止包裹执行的行为。

那么我来个沙盒可写加执行失败才请求授权呢

approval_policy = "on-failure"
sandbox_mode = "workspace-write"

结果

  • 执行ls → 直接执行并被识别
  • 执行apply_patch和rm → 请求授权

???这就不对了吧,不是都允许了吗?

于是我去掏官方文档

A more relaxed policy is workspace-write. When specified, the current working directory for the Codex task will be writable (as well as $TMPDIR on macOS). Note that the CLI defaults to using the directory where it was spawned as cwd, though this can be overridden using --cwd/-C.
一个更宽松的策略是 workspace-write。当指定此策略时,Codex 任务的当前工作目录将是可写的(在 macOS 上也包括 $TMPDIR)。请注意,CLI 默认使用其启动时所在的目录作为 cwd,不过可以使用 --cwd/-C 来覆盖此设置。

确实是这样说的。

但很明显,我们的实验结果是不可以。于是我又去掏官方文档,终于发现一个描述

To disable sandboxing altogether, specify danger-full-access like so:

``
# same as `--sandbox danger-full-access`
sandbox_mode = "danger-full-access"
``
This is reasonable to use if Codex is running in an environment that provides its own sandboxing (such as a Docker container) such that further sandboxing is unnecessary.

Though using this option may also be necessary if you try to use Codex in environments where its native sandboxing mechanisms are unsupported, such as older Linux kernels or on Windows.

要完全禁用沙盒机制,可以这样指定 danger-full-access:

# 等同于 `--sandbox danger-full-access`
sandbox_mode = "danger-full-access"

如果 Codex 运行在提供自己沙盒机制的环境中(如 Docker 容器),那么使用此选项是合理的,因为不需要额外的沙盒隔离。

不过,如果你尝试在 Codex 原生沙盒机制不受支持的环境中使用它,比如较旧的 Linux 内核或 Windows 系统,也可能需要使用此选项。

也就是说在win上,如果你不想猛猛点同意,你基本就得开这玩意。

sandbox_mode = "danger-full-access"

或者--yolo启动。

但其实我当时遇到的情况比现在还要复杂,以至于我需要使用源码编译最新版本来使用。因为当时这个pr Auto-approve DangerFullAccess patches on non-sandboxed platforms by Sing303 · Pull Request #2988 · openai/codex · GitHub 还没发版!!!

当然,虽然我们搞明白了非常左右脑互博的win上的沙盒设定,但由于codex在win上喜欢默认包裹命令执行的问题,如果不禁止这种行为,还是会很折磨。比如这位

所以我专门写了一个贴

完结

9 个赞

太强了,大佬

1 个赞

我是 在 终端 使用codex 通过 /Approval 选择 Full Access (current) 就不需要一直确认 ,但是 在vscode 插件中 就没办法设置 要一直确认 很烦,试试你的方法看下

牛逼,立竿见影

windows好难 我按照谁的作业抄 结果默认是只读模式

太强了佬