實作指南 / 13 分鐘
在 sandbox 測試命令並稽核 execpolicy
依賴 guardrail 前,先觀察 filesystem denial 與 rule decision。
codex sandbox 會在 Codex 提供的 sandbox 中執行命令,可解析 permission profile、限制 readable roots/network,並在 macOS 記錄 denials。execpolicy check 會依 rule files 評估 argv 並解釋 decision。它們用來診斷 authority,不會讓危險 command 自動變安全,也不取代 OS enforcement。
已驗證 Terminal Sequence
- $
codex sandbox --permission-profile PROFILE -- command --arg - $
codex sandbox --log-denials -- command --arg - $
codex execpolicy check --pretty --rules ~/.codex/rules/default.rules -- gh pr view 7888
工作原則
Enforcement 與 policy 不同
Sandbox 在 OS boundary 限制 process;execpolicy 分類 command intent,兩個結果都要保留。
Profile 要在 context 中解析
Working directory、config layers 與 managed requirements 會改變 effective profile。
Denial 是 evidence
Denial log 顯示缺少 capability;應縮小調整 profile,而非整體關閉保護。
實地程序
- 01
選最小 probe
用 non-destructive command 只碰一種 capability,產生可觀察 success/denial。
- 02
解析 intended profile
設定 -C 與 exact profile;production 會載入 managed config 時才 include。
- 03
擷取 denials
支援的 macOS 用 --log-denials;分享前檢查敏感 local paths。
- 04
評估 command rules
用 agent 真正會提出的 argv shape 執行 execpolicy check,讀取 matched rule/decision。
- 05
測 negative cases
證明必要命令成功,同時鄰近但不允許的 command 仍 denied。
PASS / FAIL
驗收清單
- Probe harmless 且 scoped。
- Effective profile/CWD 有記錄。
- 不混淆 sandbox 與 execpolicy。
- Negative tests 維持 denied。
- Rule 沒有意外 broad shell wildcard。
WATCH / REJECT
失敗模式
- 為單一 denial 開 danger-full-access。
- 測試與 production 不同 argv。
- 把 evolving execpolicy 當永久 API。