codex-sandbox
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCodex Sandbox Skill
Codex Sandbox Skill
LIBRARY-FIRST PROTOCOL (MANDATORY)
优先使用库协议(强制性要求)
Before writing ANY code, you MUST check:
在编写任何代码之前,你必须完成以下检查:
Step 1: Library Catalog
步骤1:库目录
- Location:
.claude/library/catalog.json - If match >70%: REUSE or ADAPT
- 位置:
.claude/library/catalog.json - 若匹配度>70%:复用或适配
Step 2: Patterns Guide
步骤2:模式指南
- Location:
.claude/docs/inventories/LIBRARY-PATTERNS-GUIDE.md - If pattern exists: FOLLOW documented approach
- 位置:
.claude/docs/inventories/LIBRARY-PATTERNS-GUIDE.md - 若存在对应模式:遵循文档中记录的实现方式
Step 3: Existing Projects
步骤3:现有项目
- Location:
D:\Projects\* - If found: EXTRACT and adapt
- 位置:
D:\Projects\* - 若找到相关内容:提取并适配
Decision Matrix
决策矩阵
| Match | Action |
|---|---|
| Library >90% | REUSE directly |
| Library 70-90% | ADAPT minimally |
| Pattern exists | FOLLOW pattern |
| In project | EXTRACT |
| No match | BUILD (add to library after) |
| 匹配度 | 操作 |
|---|---|
| 库匹配度>90% | 直接复用 |
| 库匹配度70-90% | 最小程度适配 |
| 存在对应模式 | 遵循模式 |
| 已在项目中存在 | 提取使用 |
| 无匹配项 | 构建完成后添加至库中 |
Purpose
用途
Execute code in Codex's fully isolated sandbox environment for safe experimentation with untrusted or risky code.
在Codex的完全隔离沙箱环境中执行代码,安全地测试不可信或存在风险的代码。
Unique Capability
独特能力
What Claude Can't Do: Claude runs in your environment. Codex sandbox provides:
- Network DISABLED: No external connections
- CWD only: Cannot access parent directories
- OS-level isolation: macOS Seatbelt or Docker
- Resource limits: CPU, memory constraints
- Safe experimentation: Can't break your system
Claude无法实现的功能:Claude运行在你的本地环境中,而Codex沙箱提供以下特性:
- 禁用网络:无法建立外部连接
- 仅允许访问当前工作目录(CWD):无法访问上级目录
- 系统级隔离:基于macOS Seatbelt或Docker实现
- 资源限制:对CPU、内存进行约束
- 安全实验:不会破坏你的系统
When to Use
使用场景
Perfect For:
适用场景:
- Running untrusted code safely
- Risky refactoring experiments
- Testing code with potential bugs
- Isolated prototyping
- Security research
- Experimental dependencies
- 安全运行不可信代码
- 高风险重构实验
- 测试存在潜在bug的代码
- 隔离式原型开发
- 安全研究
- 测试实验性依赖包
Don't Use When:
不适用场景:
- Need network access
- Need to access files outside project
- Production debugging
- 需要网络访问权限
- 需要访问项目外部文件
- 生产环境调试
Usage
使用方法
bash
undefinedbash
undefinedBasic sandbox execution
基础沙箱执行
/codex-sandbox "Refactor auth system and run tests"
/codex-sandbox "Refactor auth system and run tests"
With iteration limit
设置迭代次数上限
/codex-sandbox "Fix all tests" --max-iterations 10
/codex-sandbox "Fix all tests" --max-iterations 10
Risky experiment
高风险实验
/codex-sandbox "Try experimental algorithm implementation"
undefined/codex-sandbox "Try experimental algorithm implementation"
undefinedCLI Command
CLI命令
bash
codex --full-auto --sandbox true --network disabled "Your task"bash
codex --full-auto --sandbox true --network disabled "Your task"Via script
通过脚本调用
CODEX_MODE=sandbox bash scripts/multi-model/codex-yolo.sh "Task" "id" "." "10" "sandbox"
undefinedCODEX_MODE=sandbox bash scripts/multi-model/codex-yolo.sh "Task" "id" "." "10" "sandbox"
undefinedIsolation Layers
隔离层级
| Layer | Protection |
|---|---|
| Network | DISABLED - no external connections |
| Filesystem | CWD only - no parent access |
| OS-Level | Seatbelt (macOS) / Docker |
| Process | Subprocess jail with limits |
| Commands | Blocked: rm -rf, sudo, etc. |
| 层级 | 防护能力 |
|---|---|
| 网络层 | 禁用网络 - 无法建立外部连接 |
| 文件系统层 | 仅允许访问当前工作目录 - 无法访问上级目录 |
| 系统层 | 基于Seatbelt(macOS)/ Docker实现 |
| 进程层 | 带资源限制的子进程沙箱 |
| 命令层 | 禁用危险命令:rm -rf、sudo等 |
Integration Pattern
集成模式
javascript
// 1. Run risky refactoring in sandbox
const result = await codexSandbox("Refactor entire auth system");
// 2. If successful, apply to real codebase
if (result.tests_pass) {
Task("Coder", "Apply sandboxed changes to main", "coder");
}javascript
// 1. 在沙箱中运行高风险重构任务
const result = await codexSandbox("Refactor entire auth system");
// 2. 若执行成功,将变更应用至真实代码库
if (result.tests_pass) {
Task("Coder", "Apply sandboxed changes to main", "coder");
}Memory Integration
内存集成
- Key:
multi-model/codex/sandbox/{session_id} - Contains: commands, files created/modified, test results
- 存储键:
multi-model/codex/sandbox/{session_id} - 存储内容:执行的命令、创建/修改的文件、测试结果