This repo is what I currently use to sandbox my development environment for Codex CLI, shared in the spirit of openness. It runs Codex in a Docker container and mounts your repo and default Codex config. It has helper flows that creates/cleans a dedicated git worktree and launches the container against it, to enable isolated parallel sessions.
docker build -t codex-cli:local .Add this to your ~/.zshrc:
source /path/to/sandbox-docker/scripts/codex-worktrees.zshReload your shell:
source ~/.zshrcOptional: copy the default rules template:
mkdir -p ~/.codex/rules
cp /path/to/sandbox-docker/default.example.rules ~/.codex/rules/default.rulesOptional: integrate the example config into your local Codex config:
mkdir -p ~/.codex
cat /path/to/sandbox-docker/config.example.toml >> ~/.codex/config.tomlStart a Codex session in a dedicated git worktree + branch:
cxhere mpm/my-featureCleanup when you're done:
cxclose mpm/my-featureList active Codex worktrees and flag anything prunable/stale:
cxlistdocker run --rm -it \
--init \
--cap-drop=ALL \
--security-opt=no-new-privileges \
--pids-limit=256 \
--read-only \
--tmpfs /tmp:rw,noexec,nosuid,nodev \
--tmpfs /home/codex:rw,noexec,nosuid,nodev,size=512m,uid=10001,gid=10001 \
-v "$worktree_dir":/workspace:rw \
-v "$HOME/.gitconfig":/home/codex/.gitconfig:ro \
-v "$HOME/.codex":/home/codex/.codex:rw \
"${env_file_arg[@]}" \
-e CODEX_HOME=/home/codex/.codex \
-e NPM_CONFIG_CACHE=/home/codex/.npm \
-w /workspace \
codex-cli:local \
--dangerously-bypass-approvals-and-sandbox \
--searchcxhere runs Codex in a dedicated git worktree and branch. You pass a worktree name, which is also used as the
branch name. This keeps multiple Codex sessions isolated and lets you run them concurrently in the same repo.
Slashes in the name are supported (for example mpm/my-feature) and are only sanitized for the worktree
directory on disk. Worktrees are created next to the repo in a sibling directory named
<PROJECT-DIR-NAME>-worktrees/<WORKTREENAME>.
Example paths:
/path/to/sandbox-docker
/path/to/sandbox-docker-worktrees/mpm__my-feature
Behavior notes:
- If the branch already exists and no worktree exists for it,
cxherewill reuse the branch and create a worktree. - If the target worktree directory exists on disk but is not registered with git,
cxherewill stop and print guidance. - If a worktree already exists,
cxherechecks for running containers with a bind mount to that worktree:- Exactly one container: print a message and exit 0.
- More than one: print a message and exit non-zero.
- None: launch Docker with the existing worktree.
- After creating or reusing a worktree,
cxherechecks for.agent/PLANS.mdand offers to create it from the project template if missing. - Before launching Docker,
cxherechecks for$CODEX_HOME/AGENTS.mdand offers to create it from the global template if missing. - If Docker is not running or the daemon is unreachable,
cxherewill surface the Docker error output and exit non-zero.