Open Source 6 min read

codex exec resume keeps the sandbox the first turn saved

codex exec resume reuses the sandbox its first turn saved, and the flag that changes it goes before resume. 82 launches on Codex CLI 0.174.0 and 0.173.0 show how.

A person's hands pressing a strip of masking tape over the left toggle of a worn two-gang light switch on a cracked plaster wall beside a window.

The second stage of my two-stage pipeline exited 0 and changed nothing, three runs out of three, and git diff was empty. The first stage had been plain codex exec, and that is the whole story. Codex CLI 0.174.0 saves the sandbox and the approval policy on the first turn of a chat. codex exec resume carries both forward without asking.

My verdict is short. The first codex exec of any chain decides the permissions, so write them in config.toml before that turn. Then codex exec resume is a clean way to run a review, then a fix. When a saved read-only chat has to write, the line is codex exec --sandbox danger-full-access resume --last, flag in front of resume. Skip that and you get a green job that wrote nothing.

Terminal capture of codex exec resume on 0.174.0: the -s flag is rejected with exit 2, -c sandbox_mode=danger-full-access writes b.txt, and -c approval_policy=never alone leaves the folder untouched.
Left, a chat saved as read-only and resumed three ways. Right, the approval switch on its own. Trimmed from the 4 December runs.

What is Codex CLI for?

Codex CLI is OpenAI’s coding agent for the terminal: you describe a change, it reads the folder, edits files and runs shell commands. The openai/codex repository showed 137,273 stars when I read the GitHub API (api.github.com/repos/openai/codex) at 05:05 UTC on 4 December 2026. That is the most of any open-source coding agent I checked once yesterday’s opencode is set aside.

The part that matters for scripts is codex exec, the non-interactive mode. The non-interactive page says that by default it “runs in a read-only sandbox”, and it shows a two-stage pipeline: codex exec "review the change for race conditions", then codex exec resume --last "fix the race conditions you found". I ran that pipeline.

The release is rust-v0.174.0, stable at 02:05 UTC on 4 December. Its notes say codex exec “inherits the saved policy and reviewer when resuming” and that “read-only chats retain their restrictions across repeated resumes”. Pull request 63515 is the source; before it codex exec forced approvals to never.

How do you set up codex exec so every resume starts right?

I installed the release under /tmp with Node 22 and gave it an OpenAI API key in CODEX_API_KEY:

$ npm i --prefix /tmp/w4/npm @openai/codex@0.174.0
$ codex --version
codex-cli 0.174.0

Every run used a fresh git folder holding one util.py, a command-line prompt, < /dev/null on stdin and the default model, gpt-6.2-sol. For the docs pipeline, util.py held def add(a, b): return a - b beside a test expecting add(2, 3) == 5.

The one line that matters goes in config.toml under CODEX_HOME, which is ~/.codex by default:

sandbox_mode = "danger-full-access"
approval_policy = "never"

With that file in place, a plain codex exec printed approval: never and sandbox: danger-full-access in its header, wrote the file three of three, and printed no warning. The docs say to use danger-full-access only in a controlled environment such as an isolated CI runner or container; on a host with working bubblewrap, sandbox_mode = "workspace-write" is the line you want. Here the kernel refuses user namespaces. workspace-write dies with bwrap: No permissions to create a new namespace, so I measured the full-access line.

On the command line the same choice is -s danger-full-access on the first codex exec. On a resume the flag moves in front of the word resume, as the next section shows.

What goes wrong with codex exec resume?

Both come from the first turn being sticky.

The default chat is read-only and the job still passes

A bare codex exec "create a file notes.txt containing the word hello" on 0.174.0 printed approval: on-request in the header and a warning that “This thread is configured to ask a human for approval”, because codex exec “runs non-interactively and immediately rejects approval requests it receives”. The file did not appear, three of three. Exit code 0, 3 to 5 seconds, 15,330 to 15,493 tokens.

The same prompt on 0.173.0 printed approval: never, no warning, and also wrote nothing, three of three. The warning is the new part.

The docs pipeline lands in the same place. Stage 1 was codex exec "review util.py against test_util.py and say what is wrong" with no flags, stage 2 was codex exec resume --last "fix the bug you found". Both stages exited 0 and git diff was empty after stage 2, three of three, and the stage 2 header read sandbox: read-only. On this kernel stage 1 could not list the folder at all, so both stages ended by asking me to paste the files in. That is the bwrap failure. The saved policy’s own message, in the bare write runs, was “The workspace is read-only, and the write approval request failed.”

With -s danger-full-access on stage 1 and nothing on stage 2, the second header read sandbox: danger-full-access. util.py came out as return a + b with the test passing, three of three, at 16,238 to 16,263 tokens.

The release note’s promise holds: six of six bare resumed turns kept the read-only sandbox and wrote neither b.txt nor c.txt. The same rule carries a full-access first turn into a bare resume. Three of three wrote b.txt with no flags at all.

The sandbox flag goes before resume, and the switch you reach for is the wrong one

The obvious try on a read-only chat: codex exec resume --last -s danger-full-access "now create b.txt". It exited 2 with error: unexpected argument '-s' found, three of three, and no model call. codex exec resume --help has no sandbox flag of its own. The docs page says to pass -C or --sandbox before resume.

Put the flag before the word and it works. codex exec --sandbox danger-full-access resume --last "now create b.txt" on a chat saved as read-only printed sandbox: danger-full-access in the header and wrote b.txt, three of three, at 16,472 to 16,515 tokens. A bare third turn wrote c.txt too, three of three: the widened sandbox stays.

The next reach is the approval switch the warning recommends. I resumed a read-only chat with -c approval_policy=never. The header changed to approval: never and the sandbox stayed read-only. The sandbox refused the write instead of a human: b.txt was absent three of three, exit code 0.

A config override on the resume, -c sandbox_mode=danger-full-access, does the same from behind: it took a read-only chat to full access and wrote b.txt three of three.

Editing config.toml does not reach a chat that already exists. I started a chain with no config, wrote the full-access file after turn 1, and resumed with no flags. b.txt stayed absent three of three, and the header still read sandbox: read-only. Same lesson as the AGENTS.md post on 1 December, where a rule file on disk was not applied and the run still exited 0.

What did I actually run?

Eighty-five launches on 4 December 2026, 76 between 05:05 and 05:13 UTC and nine at about 09:50, with 82 reaching the model: 79 on 0.174.0 and 3 on 0.173.0, for 1,283,498 tokens. The other 3 were the -s flag behind resume, rejected by the parser.

First turnResumeResult
no flags, no confignonenotes.txt absent, exit 0, 3 of 3
-s danger-full-accessno flagssecond file written, 3 of 3
-s read-onlyno flags, twiceboth files absent, 6 of 6
-s read-only-s danger-full-access after resumeexit 2, parser rejects -s, 3 of 3
-s read-only--sandbox danger-full-access before resume, then no flagsboth later files written, 3 of 3
-s read-only-c approval_policy=neverheader approval: never, file absent, 3 of 3
-s read-only-c sandbox_mode=danger-full-access, then no flagsboth later files written, 3 of 3
no config, then config.toml set to full accessno flagsfile absent, header unchanged, 3 of 3
config.toml set before turn 1nonefile written, no warning, 3 of 3
review, no flagsfix, no flagsutil.py unchanged, exit 0, 3 of 3
review, -s danger-full-accessfix, no flagsutil.py fixed, test passes, 3 of 3

Every exit code I recorded was 0, including the runs that changed nothing; the only 2s were the parser’s three rejections. Check the folder, not the exit code: git status --porcelain after codex exec catches every no-op above.

Use codex exec resume for review-then-fix pipelines when the first turn sets the sandbox and the config file is written before the first turn. When a saved chat has to write, put --sandbox danger-full-access in front of resume, never behind it. Skip it for any chain where you cannot say what the first turn saved.

Dominic Plouffe

CTO of Trellis, with exits at FuseTalk, 360pi and DeadHeat. I write about making agents and big data work together safely, and I'm building yaaf, an open-source platform for running teams of AI agents that actually finish the job: dplouffe.ca/yaaf