Contents
- 01Start From Zero and Choose the Right Surface
- 02Turn Intent Into Verifiable Work
- 03Configure Codex and Teach It the Project
- 04Bound Authority With Sandbox and Approvals
- 05Make the Change and Prove It
- 06Work Across Environments and Worktrees
- 07Delegate With Subagents
- 08Build the Extension Stack
- 09Automate, Embed, and Run Long Work Safely
- 10Capstone: From Command to Receipt
Bound Authority With Sandbox and Approvals
Give Codex enough access to finish the work while protecting unrelated files, credentials, external systems, and irreversible actions.
By the end
A least-authority plan that separates routine local work, network access, external side effects, and destructive actions into reviewable boundaries.
The sandbox is the default boundary
A sandbox limits what commands and file operations can reach. It turns accidental or misunderstood actions into contained failures instead of broad changes. When a legitimate command is blocked, the lesson is not automatically that the sandbox is wrong. First check whether the task can succeed with a narrower path, a read-only alternative, or an existing approved tool.
Local and cloud environments may enforce boundaries differently, so inspect the current surface's official controls. The durable practice is to start with the minimum needed access, observe the specific blocker, and widen only the exact capability required for the named task.
Choose one permission engine before tuning authority
For a fresh setup, use the newer permission-profile engine: `default_permissions = ":read-only"` for inspection, `default_permissions = ":workspace"` for ordinary workspace editing, or a named policy under `[permissions.<name>]` for narrower filesystem and network rules. The colon-prefixed names are permission profiles. They are selected by `default_permissions`, not by the CLI `--profile` flag.
The compatibility engine is the older `sandbox_mode` system: `read-only`, `workspace-write`, or `danger-full-access`, optionally paired with `approval_policy` values such as `untrusted`, `on-request`, and `never`. It is selected by `sandbox_mode`, `[sandbox_workspace_write]`, or `--sandbox`. The two engines do not compose: never load `default_permissions` or `[permissions]` together with older sandbox settings. Any loaded `sandbox_mode` or `--sandbox` flag makes Codex use the older engine. In the interactive CLI, `/permissions` helps inspect the active boundary, but it does not make a mixed configuration valid.
Handle a real denial instead of fighting it
When Codex is denied, read four things: the attempted command or tool, the target path or network destination, the active sandbox, and whether an approval channel exists. If the requested effect is outside the task, keep the denial. If the task genuinely requires it, ask Codex for the narrowest alternative and review the exact escalation rather than changing the whole session to full access.
A denial can be the intended test. In a read-only session, request a harmless file creation and confirm it fails. In `workspace-write`, request the same file inside the repository and confirm it succeeds, then ask for a sibling-directory write and decline the escalation. In non-interactive execution, a newly required approval cannot be answered, so the action fails and must be represented in the run receipt.
Approval is a decision, not a dialog to dismiss
A useful approval request explains the command or action, exact target, expected effect, why the current boundary blocks it, and whether the change is reversible. Review that substance. Repeatedly clicking approve trains you to ignore the moments where human judgment is most valuable.
Broad reusable approvals are appropriate only when the command family, target scope, and effect are genuinely predictable. Installing dependencies in one known project is different from approving arbitrary package-manager commands across the computer. Publishing one named site is different from granting unrestricted provider mutations.
Protect secrets and external people
Secrets should enter through an approved credential or environment mechanism, not prompts, source files, screenshots, or logs. The agent often needs to know that a variable exists, but rarely needs to print its value. If a secret is exposed, treat it as compromised and rotate it rather than merely deleting the visible line.
External communication, production changes, purchases, account changes, and actions affecting other people require explicit authority. Drafting an email is not sending it. Preparing deployment assets is not publishing them. Keep the transition from preparation to consequence visible and reviewable.
Make safety part of completion
A completion receipt should state which permissions were used, which external systems changed, and which consequential actions did not occur. For production work, include a rollback target and independent verification. For sensitive data, include evidence that values were not written to source or logs.
Safety is not a separate phase added after implementation. The authority plan shapes the implementation itself: read before write, draft before send, stage before publish, test a migration before applying it, and resolve exact deletion targets before removing anything.
Working reference
Commands and patterns
New permission engine: inspect only
codex --config 'default_permissions=":read-only"'
Use this only after confirming that no loaded config contains older sandbox keys and the launch command does not pass `--sandbox`. The built-in permission profile denies local writes.
New permission engine: workspace editing
codex --config 'default_permissions=":workspace"'
This selects the built-in workspace permission profile for a single launch. A custom `[permissions.<name>]` policy is better when the project needs narrower filesystem or network rules.
Older sandbox compatibility engine
codex --sandbox workspace-write --ask-for-approval on-request
Use this only after removing the newer permission-profile keys from every loaded config layer. The `--sandbox` flag deliberately selects the older engine for this session.
Denial drill prompt
Create `permission-drill.txt` in this repository with the word `inside`. Then propose, but do not bypass approval for, creating `../outside-permission-drill.txt`. Report the exact result of each operation.
Use this prompt only in a disposable repository. Approve the in-workspace write if asked, reject the sibling-directory escalation, inspect the results, and remove the in-workspace drill file afterward.
When the happy path breaks
Failure modes
Symptom
A blocked command leads immediately to a request for full filesystem or network access.
Likely cause
The agent or operator optimized for convenience without isolating the actual missing capability.
Recovery
Identify the exact target and effect, try a narrower or read-only path, and approve only the smallest reusable command family when its behavior is predictable.
Symptom
A secret appears in a prompt, log, screenshot, artifact, or committed file.
Likely cause
Credential setup was handled as ordinary text rather than through a secure secret mechanism.
Recovery
Revoke and rotate the credential, remove exposed material where appropriate, audit downstream access, and document a secure setup path that never prints the value.
Symptom
Codex sends, publishes, deletes, purchases, or changes an account while the user expected only preparation.
Likely cause
The task did not distinguish draft authority from execution authority.
Recovery
Stop further mutations, recover or roll back if possible, and define explicit approval gates for the final consequential step.
Symptom
A destructive command resolves to a broader target than intended.
Likely cause
The target depended on an unchecked variable, wildcard, current directory, or ambiguous path.
Recovery
Resolve and display the exact targets with read-only checks, use explicit narrow paths, and prefer a reversible operation or backup before proceeding.
Hands-on lab
Design three authority profiles
Create least-authority boundaries for investigation, implementation, and release of the same feature.
- 01Use a disposable Git repository and record its root, current status, the absence of both permission-drill files, and every loaded config or launch flag that can select an authority engine.
- 02Choose one lane in writing. For the recommended permission-profile lane, confirm there is no `sandbox_mode`, `[sandbox_workspace_write]`, or `--sandbox`; for the older compatibility lane, confirm there is no `default_permissions` or `[permissions]`. Do not run both lanes in one loaded setup.
- 03Permission-profile lane: launch the `:read-only` command, ask for the inside drill file, and save the denial. Then launch the `:workspace` command, run the denial-drill prompt, allow the repository write, and reject or record the sibling-directory denial without widening the profile.
- 04Older compatibility lane instead: after removing all newer permission-profile settings, run `codex --sandbox read-only --ask-for-approval on-request` for the denial, then the documented `workspace-write` command for the in-workspace edit and rejected sibling request.
- 05Run `git status --short`, confirm only the intended in-workspace file exists, then have Codex remove it inside the workspace and verify a clean result.
- 06List the files, commands, network destinations, connected services, and external effects a real feature could involve; define investigation, implementation, and release authority policies without switching permission engines.
- 07For each action that should remain blocked, write the expected denial. For each legitimate boundary crossing, write an escalation naming the exact target, effect, reason, and rollback.
Deliverable: An authority matrix plus captured evidence of a read-only denial, a successful in-workspace edit, a rejected out-of-workspace request, and one release gate.
Reusable artifact
Authority and approval matrix
A reusable way to grant only the access a task stage requires.
Task stage: [investigate / implement / verify / release] Filesystem read scope: [paths] Filesystem write scope: [paths or none] Allowed commands: [families and purpose] Network access: [destinations and reason] External services: [service + read/draft/write scope] Sensitive data: [names, approved access route, prohibited outputs] Consequential actions: [action + required approver] Destructive actions: [target resolution + backup or recovery] Rollback: [how to return to prior state] Receipt: [how authority use will be reported]
Before you move on
Receipt checklist
- Each task stage has an explicit filesystem, command, network, and external-service scope.
- At least one out-of-scope action is demonstrably denied.
- Any escalation names the exact target, effect, and reason rather than requesting general access.
- No credential value appears in source, conversation artifacts, logs, or screenshots.
- Consequential actions have a visible human approval and rollback boundary.
Primary sources
