进入codex后,如何检验codex是否在bubblewrap沙箱运行

前言 ⚠ 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介绍:

  1. Bubblewrap(bwrap) 是 Linux 上一个轻量级沙箱工具(基于 Linux namespaces,如 mount namespace、user namespace、PID namespace 等),常用于 Flatpak 等项目。它能为进程创建一个受限的视图,限制其对文件系统、设备、网络等的访问。

    Bubblewrap 可以让 Codex 只看到受限的文件系统视图:例如只读挂载根目录、只写当前项目目录(workspace)、临时目录 /tmp,而无法随意访问 ~/.ssh、/etc、home目录其他部分或系统关键文件,限制命令能看到/访问什么文件系统、网络等

    控制 Codex 执行的 shell 命令和 AI 生成代码的运行环境,避免它意外(或故意)破坏系统、窃取密钥、泄露数据。这是 Codex "Harness"(控制层)的重要组成部分

  2. 精细控制访问权限:

    • 支持不同 sandbox 模式,例如:
      • workspace-write:允许修改项目目录,但严格限制其他地方。
      • danger-full-access:完全禁用沙箱(不推荐日常使用)。
    • 可以结合 --ro-bind(只读绑定)、--tmpfs 等参数定制隔离级别。
  3. 比 Docker 等容器更轻量:

二、Codex 的 approval policy(批准策略)和 execpolicy(执行策略)

  • agent可能会执行不可预测的命令(比如删除文件、访问敏感目录、运行恶意脚本),可以通过policy弹出提醒

三、在codex中检验是否在bubblewrap中

  1. 在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.
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  1. 从输出可以非常明确地判断正在 Bubblewrap 沙箱中:
  • bwrap 存在且正在运行
    which bwrap 返回了 /usr/bin/bwrap

  • PID 1 是 bwrap 进程(最有力的证明)

    bash 复制代码
    bwrap --new-session --die-with-parent --ro-bind / / --dev /dev --bind /tmp /tmp --perms 555
    • 这是 bubblewrap 创建沙箱的典型命令。
    • --ro-bind / / 表示把整个根目录以只读方式绑定进来,实现了沙箱隔离。
    • PID 1 是 bwrap,说明你的整个 shell 环境都是被 bwrap 包裹起来的。
  1. 当前的 shell(PID 2)是在这个沙箱内运行的子进程。

相关推荐
沧沧凉凉20 小时前
一段需求、零素材,Claude Code 派了 33 个代理给我做了个 3D 动作游戏
游戏·ai编程·three.js
小虎AI生活20 小时前
315 之后 AI 改规矩了,怎么让豆包和 DeepSeek 认得出你
aigc·ai编程
郑州光合科技余经理21 小时前
海外版外卖加盟:总站与分站配送规则怎么分开管
java·开发语言·前端·后端·uni-app·php·ai编程
熊猫钓鱼>_>1 天前
Kotlin Multiplatform for OpenHarmony 实战:为 Reaktive 实现响应式原语适配(完整版 · 含摘要目录与技术图表)
华为·kotlin·大模型·ai编程·harmonyos·适配·reaktive
姜楠聊AI转型1 天前
AI 编程安全合规怎么落地?三大风险 + 四道防线(数据脱敏 / 漏洞左移 / 审计 / 权限路由)
ai编程·vibe coding·ai coding·coding agent
熊猫钓鱼>_>1 天前
Kotlin Multiplatform for OpenHarmony 实战:为 MVIKotlin 实现单向数据流适配
华为·ai编程·鸿蒙·openharmony·适配·数据流·mvkotlin
Alice-YUE1 天前
前端 × AI:从 Cursor 到 Transformer,一份完整认知路径
前端·人工智能·transformer·ai编程·前端开发·cursor
FanetheDivine1 天前
学习Agent开发 10.延迟工具 deferred tools
agent·ai编程