前言 ⚠ Codex could not find bubblewrap on PATH.
error:
bash
Install bubblewrap with your OS package manager.
See the sandbox prerequisites:
https://developers.openai.com/codex/concepts/sandboxing#prerequisites.
Codex will use the vendored bubblewrap in the meantime.
Codex 在 Linux / WSL2 上默认使用 Bubblewrap 作为其沙箱后端(也会结合 seccomp 等进一步加固)。系统会优先使用你通过包管理器安装的 bwrap(如 sudo apt install bubblewrap),否则回退到内置版本。
一、bubblewrap介绍:
-
Bubblewrap(bwrap) 是 Linux 上一个轻量级沙箱工具(基于 Linux namespaces,如 mount namespace、user namespace、PID namespace 等),常用于 Flatpak 等项目。它能为进程创建一个受限的视图,限制其对文件系统、设备、网络等的访问。
Bubblewrap 可以让 Codex 只看到受限的文件系统视图:例如只读挂载根目录、只写当前项目目录(workspace)、临时目录 /tmp,而无法随意访问 ~/.ssh、/etc、home目录其他部分或系统关键文件,限制命令能看到/访问什么文件系统、网络等
控制 Codex 执行的 shell 命令和 AI 生成代码的运行环境,避免它意外(或故意)破坏系统、窃取密钥、泄露数据。这是 Codex "Harness"(控制层)的重要组成部分
-
精细控制访问权限:
- 支持不同 sandbox 模式,例如:
workspace-write:允许修改项目目录,但严格限制其他地方。danger-full-access:完全禁用沙箱(不推荐日常使用)。
- 可以结合
--ro-bind(只读绑定)、--tmpfs等参数定制隔离级别。
- 支持不同 sandbox 模式,例如:
-
比 Docker 等容器更轻量:
二、Codex 的 approval policy(批准策略)和 execpolicy(执行策略)
- agent可能会执行不可预测的命令(比如删除文件、访问敏感目录、运行恶意脚本),可以通过policy弹出提醒
三、在codex中检验是否在bubblewrap中
- 在codex中执行下面的代码
bash
which bwrap || echo "bwrap not in PATH"; ps aux | grep -E 'bwrap|codex' | head -10
输出:
bash
› which bwrap || echo "bwrap not in PATH"; ps aux | grep -E 'bwrap|codex' | head -10
• Running both checks now: bwrap availability and active bwrap/codex processes.
• Ran which bwrap || echo "bwrap not in PATH"; ps aux | grep -E 'bwrap|codex' | head -10
└ /usr/bin/bwrap
jimyshow 1 0.0 0.0 3596 1360 ? S<s 11:21 0:00 bwrap --new-session --die-with-parent --ro-bind / / --dev /dev --bind /tmp /tmp --perms 555
... +83 lines (ctrl + t to view transcript)
jimyshow 2 0.0 0.0 7744 3424 ? S< 11:21 0:00 /bin/bash -c which bwrap || echo "bwrap not in PATH"; ps aux | grep -E 'bwrap|codex' | head -10
jimyshow 5 0.0 0.0 6948 2244 ? S< 11:21 0:00 grep -E bwrap|codex
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• Results:
- bwrap is available at /usr/bin/bwrap.
- There is an active sandbox process using bwrap (PID 1) launching a codex binary internally.
- Your shell still cannot run codex directly because it is not on PATH, even though the harness uses an internal codex binary under Node modules.
If you want, I can next check whether that internal binary path is invokable directly from this shell.
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
- 从输出可以非常明确地判断正在 Bubblewrap 沙箱中:
-
bwrap 存在且正在运行
which bwrap返回了/usr/bin/bwrap -
PID 1 是 bwrap 进程(最有力的证明)
bashbwrap --new-session --die-with-parent --ro-bind / / --dev /dev --bind /tmp /tmp --perms 555- 这是 bubblewrap 创建沙箱的典型命令。
--ro-bind / /表示把整个根目录以只读方式绑定进来,实现了沙箱隔离。- PID 1 是 bwrap,说明你的整个 shell 环境都是被 bwrap 包裹起来的。
- 当前的 shell(PID 2)是在这个沙箱内运行的子进程。