By JayNovember 2026
Are We All Running Codex Wrong?
Codex (OpenAI's coding agent) ships safe: it works in your project folder, has no network and asks before it steps outside. That is a sound default. The trouble is how it fails. When the sandbox blocks something, the error says DNS, and approving a complex script saves it as a rule that (in our file) was usually never reused.
This is about interactive use: you at the keyboard, working with the agent turn by turn. Our unattended agent will run differently, on a separate account with no administrator rights and no internet, so the network setting below applies to interactive sessions only. We tested the mechanisms on Codex 0.167.0, and the usage figures come from our own account.
What the defaults are
Codex's security documentation recommends "Version-controlled folders: Auto (workspace write + on-request approvals)". On network access it says:
...the default workspace-write sandbox mode keeps network access turned off unless you enable it in your configuration
Our config.toml sets sandbox_mode = "workspace-write" and approval_policy = "on-request", which matches that recommendation. The log figures cover September 8 to November 6 and span the versions we ran, and the logs were still growing when we counted, so totals can differ by a few calls.
Default 1: the sandbox error looks like a DNS failure
We ran a command through the Codex sandbox helper with network_access=false and looked at what it contains:
- One network interface exists in
/proc/net/dev, the loopback (lo). Nothing else. /etc/resolv.confis unchanged. It still names the real resolver, which the sandbox cannot reach.- A lookup by name fails with
curl: (6) Could not resolve host: github.com. - A connection by IP address fails differently, with
curl: (7) Failed to connect.
The sandbox is an empty network namespace with a configured resolver that goes nowhere, so every lookup fails and the message reads as a DNS fault. Outside the sandbox the same host returned HTTP 200, and 30 ordinary lookups across three GitHub hostnames all succeeded.
None of the 62 outputs mentions the sandbox.
Our logs show how often it happens. Across 42 interactive sessions and 23,700 shell calls (1,775 of them asked for escalation, 7.5%), 62 command outputs contain a name-resolution failure in 10 sessions. The error lines name github.com 47 times, including git push exiting 128 with Could not resolve host: github.com. None of the 62 outputs mentions the sandbox.
Default 2: approval arrives after the failure
The documentation names network access as something Codex asks about. A command line does not say whether it will use the network, so something has to guess. In our logs the guess comes after the failure:
- 60 of the 62 failing commands ran without an escalation request.
- In 44 of those 60 (73%) the next shell command asked for escalation.
May I fetch GitHub main to verify the homepage release can be pushed safely?
For 44 of those 60 failures (73%), a network command cost a failed attempt, a misleading error and a prompt. The tool recovers, but the person at the keyboard sees a DNS failure first.
A command line does not say whether it will use the network, so something has to guess.
Default 3: a script is saved as one rule
Approve and remember writes a prefix rule that matches the command word for word. The prefix comes from one of two places, per Codex's source at version 0.167.0 and the rules documentation:
- The model can supply a
prefix_rulewith its request. Codex uses it unless it is empty, exactly equals an entry on a banned list, would not approve every command in the script or duplicates a rule that already matches. - Otherwise Codex derives one from the command. A plain chain joined by
&&or|is split into separate commands. A script with redirection, substitutions, environment variables, wildcards or control flow is not split, and the whole invocation becomes the rule.
The model supplies a prefix often. 1,097 of our 1,775 escalated calls (62%) carried one, spread over 124 distinct values, and 89% of those calls repeated an earlier prefix. The most common was a test script kept in a file, on 182 requests. Escalations without a prefix repeated only 9% of the time.
The fallback path, used when no prefix is supplied or Codex drops the one supplied, produces the problem rules. Our ~/.codex/rules/default.rules held 257 rules when we analyzed it (253 allow, 4 prompt), up from 245 when we wrote Are We Just Drinking Birds Now?, and 129 are whole-script rules in the form zsh -lc "<entire script>". Only 134 of the 1,775 escalated calls (7.5%) ran a script that now sits behind one, yet these rules are half the file. Of those 134 calls, 96 carried a model-supplied prefix (the logs do not show which call created each rule). The file is account-wide, so it includes rules from delegated work. To measure reuse, we counted how often each whole-script rule's exact command ran again in the interactive logs:
| Times the exact command ran | Whole-script rules |
|---|---|
| 2 or more | 39 |
| Once (the approval itself) | 80 |
| Never | 10 |
The most-reused command ran 8 times, and 90 of the 129 (70%) did not run again in our interactive logs (some of the 10 never seen may have been used in delegated sessions). That counts commands run again, not recorded rule matches (the logs do not record matches).
The scripts behind these rules look complex. Of the interactive calls that match a whole-script rule, 70% look compound (a chain, pipe, redirect or substitution, found by simple pattern matching), against 48% of calls that kept a model-supplied prefix. That fits the source's requirement that a prefix cover every command in a script. The logs do not record when a prefix is rejected, so this is the source's reading and not something we observed.
The logs do show a contrast inside one script. Run plainly, our test script has one narrow rule behind 122 requests. Run with environment variables set in front, the same script has 22 separate whole-script rules, every one beginning with the variable assignments. Across the file, 24 whole-script rules begin with environment variables, and 22 of those would have matched an existing rule of three or more words if the variables were removed.
One script, run plainly: 1 narrow rule. Run with environment variables in front: 22 whole-script rules.
Why shorter rules are not the answer
Shorter rules would make reuse jump. Counting repeat requests among the 1,775 escalated calls, a rule on the exact command would cover 254 (14%), a rule on the first two words 1,527 (86%) and a rule on the first word 1,682 (95%). Among the first words of our escalations are powershell.exe (326), ssh (276), bash (182), node (167), env (112) and python3 (95). A rule on bash or node allows any code those programs run.
Codex guards against this. A model-supplied prefix identical to one of 88 listed entries (bash -lc, node, git on its own, python3 -c) is rejected. The match is exact, so a wrapper in front changes the answer. Our rules file contains rtk proxy node, rtk proxy bash and rtk bash -lc (rtk is the third-party tool that shortens command output, described in Are We Just Drinking Birds Now?). Each was a blanket approval for the program behind it. We found them while checking this post and narrowed them: the three are gone, two rules for named script files replace them, and inline node -e and bash -lc calls are no longer pre-approved. A list cannot know every third-party wrapper, so the check is only as good as the commands it sees. Anyone running a wrapper in front of commands should search their rules file for the same pattern.
Are We Just Drinking Birds Now? found the same limit from the other side: wrapping a command in quote marks hid sudo from a prompt rule. Approval logic works on text, and the real boundary has to live on the machine. That applies to program-and-subcommand rules too: an ssh host rule is only as narrow as the limits on the remote account.
Approval logic works on text, and the real boundary has to live on the machine.
The conclusion: three fixes and one setting
You are not running Codex wrong. The defaults are right to restrict. Three things in them are worth OpenAI fixing:
- Name the cause. When a command fails inside a network-off sandbox, say so. Today the error is a resolver message.
- Say why a script cannot be saved narrowly. In our file, a call with environment variables in front became a whole-script rule 24 times, and 22 of those would have matched an existing narrower rule without the variables. A prompt that says so and suggests moving the logic into a file should turn more of them into rules that repeat.
- Warn on any rule that ends in an interpreter. The banned list compares the exact command, so a wrapper in front gets past it. A warning keyed to the last word of the rule works whatever the wrapper is.
Until then, we run network_access = true in [sandbox_workspace_write], with filesystem limits and on-request approvals unchanged. A fresh sandbox then resolved GitHub, returned HTTP 200 and read a public repository's HEAD with git ls-remote. The trade is real: outbound access is general, not limited to GitHub. According to the configuration reference, a domain allowlist (features.network_proxy.domains, active once features.network_proxy.enabled = true) can narrow it to named hosts.
Beyond that setting, this is what we run:
- Multi-step logic lives in script files, with environment variables set inside them.
- Rules we write ourselves sit at program and subcommand level (the whole-script rules came from approvals along the way).
- Each rule is tested against the exact command from the log.
- Prompts stay for the commands that matter.
- The logs get read after long sessions (the agent cannot see its own prompts).
What to take from this
- If
Could not resolve hostappears inside Codex but not in your shell, check the sandbox before you check DNS. - Read your rules file for wrapper prefixes. A rule that begins with a wrapper and ends in
nodeorbashallows any code.
If an AI agent works in your business, its defaults decide what you see and what you approve. This is the setup work we do for clients: the permissions, the logs and the checks, tested against the real commands.
Sources
- Codex agent approvals and security
- Codex configuration reference
- Codex permission rules documentation
- Codex execution policy source,
exec_policy.rsat rust-v0.167.0 - Codex on GitHub
- Our own Codex session logs (42 interactive sessions, September 8 to November 6, 2026), rules file and a sandbox test on Codex 0.167.0.