codex icon indicating copy to clipboard operation
codex copied to clipboard

0.152.0 Windows: `--ignore-user-config` leaves exec with no usable sandbox — every command "rejected: blocked by policy" (regression from 0.147.0)

Open OnTheWayx2 opened this issue 3 months ago • 3 comments

What happened

On Windows, codex exec with --ignore-user-config and --sandbox read-only refuses every shell command the model attempts — including plain reads like rg --version wrapped in powershell.exe -Command — with:

exec_command failed for `"C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe" -Command 'rg --version'`:
CreateProcess { message: "Rejected(\"... rejected: blocked by policy\")" }

The identical invocation executes fine on 0.147.0. The process still exits 0 and the model answers from the prompt alone, so automated callers get a plausible-looking response produced without the model having read anything.

Minimal reproduction (verified)

Windows 11 Pro (10.0.26200), codex-cli 0.152.0 standalone, Codex desktop app installed (so ~/.codex/config.toml contains [windows] sandbox = "elevated"):

codex exec -C <scratch-dir> --skip-git-repo-check --ignore-user-config --sandbox read-only ^
  -c model_reasoning_effort=low --json "Run the command: rg --version . Report its stdout, or the exact error if it cannot run."

→ every command rejected "blocked by policy", exit 0.

Each of the following makes the same invocation work:

  • same command on codex-cli 0.147.0;
  • removing --ignore-user-config (the user config loads, including [windows] sandbox = "elevated");
  • keeping --ignore-user-config and adding -c windows.sandbox="elevated".

What it is not (bisected)

Each of these was toggled independently on 0.152.0 with no effect: --ignore-rules, -c approval_policy="never", --ephemeral, --sandbox workspace-write instead of read-only, and a fully inherited vs. sanitized environment. codex sandbox cmd.exe /c "echo OK" also succeeds, so the restricted-token machinery itself launches processes.

Root cause (apparent)

0.152.0 moved Windows command execution onto the elevated sandbox, selected by [windows] sandbox = "elevated" in the user config. --ignore-user-config drops that selector, and instead of falling back to a working path (as 0.147.0 did) or failing loudly, the policy layer rejects every command.

--ignore-user-config is the documented way for automation to run hermetically — a config-suppressing flag silently disabling all command execution seems unintended.

Suggestions

  1. When the user config is ignored on Windows, default the exec sandbox to something usable, or emit a startup error naming the missing setting rather than rejecting each command as "blocked by policy".
  2. Consider a nonzero exit (or a machine-readable marker in --json output) when every command execution in a turn was refused — exit 0 makes this invisible to callers.

Possibly related: #38898, #40047 (elevated-sandbox helper failures with different symptoms).

OnTheWayx2 avatar Sep 02 '26 01:09 OnTheWayx2

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #41779

Powered by Codex Action

github-actions[bot] avatar Sep 02 '26 01:09 github-actions[bot]

Additional reproduction on Windows with an isolated CODEX_HOME (rather than --ignore-user-config). This appears related to #42172; I cannot yet confirm an identical root cause.

  • Codex CLI: 0.158.0-alpha.2.1.
  • The normal desktop profile has [windows] sandbox = "elevated". A separate profile for ephemeral background codex exec calls initially had no config.toml.
  • With that separate profile, a prompt asking the model to run only Get-Location under --sandbox read-only --ephemeral --json produced CreateProcess ... rejected: blocked by policy for PowerShell. The CLI exited with code 0, while the JSON stream contained no successful command_execution item. Our caller caught this by checking for a completed command item instead of trusting the process exit code.
  • Adding only project trust to the separate profile did not change the result. Changing the CLI sandbox from read-only to workspace-write did not change it either.
  • In a temporary test, adding [windows] sandbox = "elevated" to the separate profile removed the immediate policy rejection, but the model received no completed command result; the invocation was cancelled after several minutes. The temporary configuration was removed. This is not a confirmed workaround.

Expected: a supported isolated profile should either execute the permitted read-only command or fail with a nonzero process status and a machine-readable reason. Actual: the initial policy denial still allowed a successful process exit, so an automation must inspect JSON command events to detect it.

All paths and account details have been omitted. No authentication material is included.

manfred1591-lang avatar Sep 27 '26 11:09 manfred1591-lang

I can confirm the windows.sandbox="elevated" workaround, but in a hermetic environment it exposed a second Windows failure.

With codex-cli 0.153.4:

  1. --ignore-user-config --sandbox read-only with no explicit Windows selector -> CreateProcess ... rejected: blocked by policy.
  2. Adding only windows.sandbox="elevated" -> process creation succeeds, but bundled pwsh crashes during InitialSessionState -> GetSaferPolicy with Win32Exception 126 before the requested command runs.
  3. The sandbox environment had no SystemRoot.
  4. Keeping --ignore-user-config, read-only isolation, inherit="none", and explicit elevated backend, then adding only:
SystemRoot=C:\Windows

made the hermetic codex exec read-only scratch-file probe pass.

So on this machine the minimal working explicit configuration was:

windows.sandbox="elevated"
shell_environment_policy.set={SystemRoot='C:\Windows'}

No Full Access or user-config loading was required. The important point is that the elevated selector fixes the blanket policy rejection, but a sanitized environment can still fail later if SystemRoot is absent.

rza255 avatar Sep 28 '26 19:09 rza255