Agent skill
codex-sandbox
Create and manage per-task isolated git clones (sandboxes) for Codex CLI sessions, with automatic branch creation and safety hooks that block committing/pushing on main/master. Use when running multiple Codex sessions or parallel tasks and you want to avoid git worktree friction, cwd/branch mixups, or environment collisions.
Install this agent skill to your Project
npx add-skill https://github.com/regenrek/agent-skills/tree/main/skills/codex-sandbox
SKILL.md
Codex Sandboxes
Create one directory per task and run the agent inside that directory. Prefer this over git worktrees when:
- Codex or other agents sometimes use the wrong current working directory.
- You want full isolation for .env, node_modules, build outputs, ports, and dev servers.
- You want a simple mental model: one task equals one folder equals one branch.
This skill bundles a small Python CLI plus a Bash wrapper:
scripts/codex_sandbox.py(primary)scripts/codex-task(convenience)
Locate the skill directory
Run the scripts from the skill folder, depending on where you installed it:
- Repo-scoped:
$REPO_ROOT/.codex/skills/codex-sandboxes - User-scoped:
$CODEX_HOME/skills/codex-sandboxes(macOS/Linux default:~/.codex/skills/codex-sandboxes)
Use git rev-parse --show-toplevel to get $REPO_ROOT.
Quick start (agent-only)
This skill is always invoked by an agent. Do not run it manually.
Example command the agent should run:
SKILL_DIR="$(git rev-parse --show-toplevel)/.codex/skills/codex-sandboxes"
python3 "$SKILL_DIR/scripts/codex_sandbox.py" new fix-123
The command will:
- Detect the repo remote (default:
origin). - Create or update a local bare mirror.
- Clone a sandbox directory under a base directory.
- Create/switch to a task branch from
origin/main. - Set upstream tracking to
origin/<branch>(pushes once if needed). - Install safety hooks that block commit/push on
main/master.
How to instruct the agent
Always request this via the agent. Provide:
- Task name (used for sandbox + branch name).
- Any non-default base directory (e.g.
--base-dir ~/projects). - Any non-default base branch or remote.
If you do not provide extra details, the agent should use defaults. If the task name is ambiguous or missing, the agent should ask back.
Example prompt to the agent:
Use codex-sandbox to create a sandbox for task "fix-123".
Place it under ~/projects, base branch main.
Command: python3 <skill_dir>/scripts/codex_sandbox.py new fix-123 --base-dir ~/projects --base-branch main
Concepts
Use these terms consistently in prompts and logs:
- Workset: Logical grouping for a ticket/feature (optional label only).
- Sandbox: One clone directory used by one writing agent.
- Session: One Codex process running in one sandbox.
Prefer: one writing session per sandbox.
Create a sandbox
python3 <skill_dir>/scripts/codex_sandbox.py new <task> [options]
Common patterns:
# Create sandbox + branch and print its path
python3 <skill_dir>/scripts/codex_sandbox.py new feat-auth
# Use a different base branch
python3 <skill_dir>/scripts/codex_sandbox.py new fix-123 --base-branch develop
# Copy .env.example to .env on creation
python3 <skill_dir>/scripts/codex_sandbox.py new feat-auth --env-copy
Key options:
--base-dir DIR: Where to place sandboxes (default:~/wip).--bare-dir DIR: Where to keep the bare mirror (default:~/.cache/codex-sandboxes/<repo>.git).--remote NAME: Which remote to use (default:origin).--remote-url URL: Override remote URL discovery.--base-branch NAME: Base branch to branch from (default:main).--branch NAME: Explicit branch name (default: derived from<task>).--env-copy: Copy.env.exampleto.envif present and.envmissing.
List, inspect, remove
python3 <skill_dir>/scripts/codex_sandbox.py list
python3 <skill_dir>/scripts/codex_sandbox.py path <task>
python3 <skill_dir>/scripts/codex_sandbox.py status <task>
python3 <skill_dir>/scripts/codex_sandbox.py rm <task>
Safety rules
Follow these rules in every run:
- Never run a write-capable agent in the primary checkout.
- Always create a sandbox for a write task.
- Keep one writer per sandbox.
- Keep
main/masterprotected on the remote (PR-only merges).
If the sandbox is currently on main/master, the tool will refuse to proceed unless you pass --allow-main.
Multiple sessions
If you want multiple sessions for one workset, create multiple sandboxes:
python3 <skill_dir>/scripts/codex_sandbox.py new feat-auth-ui-1
python3 <skill_dir>/scripts/codex_sandbox.py new feat-auth-ui-2
python3 <skill_dir>/scripts/codex_sandbox.py new feat-auth-core-1
Avoid running two writing sessions in the same sandbox.
Troubleshooting
- Remote URL detection failed: pass
--remote-url. - Sandbox already exists: choose a unique
<task>name or remove withrm. - You want deterministic naming: read
references/naming.md.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
shadcn-vite-iconify-landing-page
Build, critique, and iterate high-converting marketing or product landing pages using React + Vite + TypeScript + Tailwind and shadcn/ui components, with all icons sourced from Iconify. Use when the user asks for a landing page, sales page, signup page, CRO improvements, above-the-fold vs below-the-fold structure, hero + CTA copy, section order, or wants production-ready shadcn + Vite code.
security-leak-guardrails
Sets up secret-leak prevention guardrails with forbidden path checks, gitleaks config, CI secret scanning, and dependency updates. Use when hardening repos against credential leaks or when adding gitleaks, trufflehog, git hooks, or security checks.
homebrew-publish
Publish CLIs/TUIs to Homebrew via a personal tap. Use when asked to create or manage a Homebrew tap repo, generate or update formulae, compute sha256, test installs, or ship new releases for Go, Rust, Node/TypeScript, Python, or prebuilt binaries.
architecture-ownership
Determine runtime owner, first-fix layer, and canonical long-term module or package owner in layered codebases. Use when placing code across UI vs platform shell vs runtime orchestration vs domain or application vs shared core vs adapter or integration layers, debugging ownership issues, removing duplicate policy paths, or answering "where should this live?" architecture questions.
codex-analysis
Run Codex CLI for deep code analysis and second-opinion reviews. Use when the user explicitly asks for Codex analysis, Codex help, or wants a second opinion from Codex on code, architecture, or debugging questions.
go-local-health
Run local Go health checks (tests, coverage, lint) in Go repositories that contain go.mod/go.sum. Use when the user asks to run or interpret local Go test/coverage/lint workflows using tools like lazygotest, gocovsh, tparse, and golangci-lint. Do not use for Rust or non-Go projects.
Didn't find tool you were looking for?