Codex desktop app on Windows injects split writable roots, causing `apply_patch` to fail before patching workspace files, forcing agents to fallback to bypass the sandbox and write files using powershell
What version of the Codex App are you using (From “About Codex” dialog)?
26.623.70822
What subscription do you have?
Pro
What platform is your computer?
Microsoft Windows NT 10.0.26100.0 x64
What issue are you seeing?
The safe edit path (apply_patch) is unusable in Codex desktop app sessions on Windows. Agents have to fall back to shell-based file rewrites inside the project, which bypasses the sandbox and is less precise and more error-prone.
The apply_patch tool call fails when patching files inside the active workspace root. The failure happens before the target file is read or modified.
Observed Error (according to agent)
apply_patch verification failed: Failed to read file to update C:\git\foobar\apps\server\src\routes\sync.ts:
failed to prepare fs sandbox:
failed to prepare windows sandbox wrapper:
windows unelevated restricted-token sandbox cannot enforce split writable root sets directly;
refusing to run unsandboxed
Observed Behavior
The desktop app provides a managed sandbox profile with multiple writable roots (C:\git\foobar and C:\tmp). On Windows, apply_patch cannot construct/enforce that split-root sandbox using the unelevated restricted-token backend, so it refuses to run at all.
What steps can reproduce the bug?
- Ensure workspace-write sandbox mode is enabled.
- Create a new session in
C:\git\foobar. - Send prompt
Create a test.txt file that says "hello world" - Observe the file is created.
- Send prompt
List the workspace roots added to this session, and also list all writable paths - Observe the only workspace root is
C:\git\foobarand writable paths areC:\git\foobar,C:\tmp,:tmpdir - Send prompt
Use theapply_patchtool to change "hello" intest.txtto "bye" - Observe agent responds with
I first triedapply_patch, but it failed because the Windows sandbox wrapper refused to run it in this restricted writable-root setup, so I made the same edit with PowerShell.
What is the expected behavior?
apply_patch should work for files inside the active writable workspace root, or the desktop app should not start Windows sessions with a sandbox shape that makes apply_patch unusable.
Additional information
The safe edit path (apply_patch) is unusable in Codex desktop app sessions on Windows. Agents have to fall back to shell-based file rewrites inside the project, which bypasses the sandbox and is less precise and more error-prone.
9 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Yeah, I'm still having this issue as of today. I've confirmed the issue is not present in the current IDE version of codex, only the windows app. I also checked older chat logs from a few weeks ago in codex and they were not having this issue, they were able to use apply_patch without errors.
I've got the same issue here when I use the codex VSCode extension.
Adding some diagnostics from my Windows setup.
Environment:
What I tried:
unelevatedandelevated.sandbox_private_desktop = false.exclude_tmpdir_env_var = trueandexclude_slash_tmp = true.Observed behavior:
sandbox = "unelevated":apply_patchadd works.apply_patchupdate/delete fails with:windows unelevated restricted-token sandbox cannot enforce split writable root sets directly; refusing to run unsandboxedsandbox = "elevated":apply_patchadd/update/delete works.CreateProcessAsUserW failed: 5sandbox_private_desktop = falsedid not change this.Wasted a bunch of tokens trying to get Sol to fix this until I found my way here. Please fix this..
I can independently reproduce this in Codex Desktop on native Windows.
Configuration:
The Desktop UI showed a single workspace root, but the managed permission profile still injected other writable locations, including temporary/runtime paths and paths previously available to the task.
Minimal test:
In one session, the patch failed before creation with:
Troubleshooting performed:
writable_rootsentry.A separate fresh-session test exhibited a closely related failure: the Add File patch succeeded, but deleting the same file through
apply_patchfailed withwindows_sandbox_helper_unknown_error. The file could then be removed through another filesystem operation. This second symptom appears to match #31229.The filename and patch body are ASCII-only and minimal. The failures occur during Windows sandbox preparation/ACL handling, before normal patch processing. This also encourages fallback to shell-based writes, bypassing the normal patch review workflow.
I can independently reproduce this on Codex Desktop for Windows with the unelevated sandbox.
Environment:
[windows] sandbox = "unelevated"Repro:
apply_patchAdd File inside the workspace succeeds.apply_patchUpdate File attempts against that existing file fail:0/5.apply_patchDelete File fails with the same error.Exact error:
I also tested the standalone Codex CLI directly in
workspace-writemode, without Desktop’s visualization root. Its effective writable roots were only:Add File still succeeded, but the first existing-file Update failed with the identical error. This shows the visualization root is not necessary to trigger the issue; the normal workspace-plus-temp root set is sufficient.
I removed legacy custom workspace/skill/plugin roots and fully restarted Desktop. I also disabled the Visualize plugin. Neither changed the failure. This is therefore not caused by user-configured roots, stale skill roots, the temporary arg0 launcher, or Visualize alone.
Security concern: in Desktop, harmless Add File probes outside the displayed writable roots were unexpectedly created, while existing-file Update/Delete fail closed. That leaves
apply_patchboth unreliable and inconsistent with the declared boundary.This appears to require a Codex Windows runtime fix. The unelevated restricted-token backend should support the effective split writable-root set, or the runtime should normalize/project its internal and temporary roots consistently before
apply_patchis invoked. A local config workaround that removes normal temp access or broadens filesystem access would not be an acceptable solution.@fcoury-oai Heads up that your merged Codex PR #31138 which was intended to fix this either didn't get merged into the new unified ChatGPT app, or it didn't resolve the issue.
This bug still persists, and 5.6 wastes even more time on working around it constantly (I frequently see the thinking text say
Planning a workaround for the sandbox apply_patch issue).There is now also an additional even worse case which is blocking development of one of my projects completely. After extended development, some corner-case issue has been hit, where apply_patch cannot be used and agents refuse to work around it even in new sessions. I'm assuming this is due to the new ChatGPT app having a stricter system prompt. Agents simply say
Blocked by the Codex patch helper: every apply_patch invocation fails because the WindowsApps executable returns “Access is denied,” including approved out-of-sandbox execution. No matter how much I've tried to get agents to bypass the sandbox restriction and use powershell for this project, they insist that their system prompt strictly prohibits bypassing the sandbox.Additional source-level evidence from
codex-cli 0.143.0and the current publicmainbranch.Observed source boundary
I reproduced the exact pre-file-access failure:
The installed 0.143.0 binary maps to tag
rust-v0.143.0, commitc4d748f586a84a3ed5b6aceb82e9a1db4abb1cda. The same refusal was still present when checked on publicmainat78ba047bdae3db0342dee11d8d9ef5582fe8ce49.The fail-closed check is in
codex-rs/sandboxing/src/windows.rs, functionresolve_windows_restricted_token_filesystem_overrides. It compares the compatibility projection writable roots with the requested split-policy roots and returns this diagnostic whenever the sets differ.The lower Windows sandbox already has much of the required representation:
WindowsSandboxFilesystemOverrides.write_roots_override--write-roots-jsonroot_capability_sidsHowever, the unelevated unified-exec branch does not forward
WindowsSandboxSessionRequest.write_roots_overrideintospawn_windows_sandbox_session_legacy. The capture path incodex-rs/core/src/exec.rssimilarly forwards the override only to the elevated backend.Two related fail-closed/atomicity gaps are relevant to a complete fix:
canonical_existingincodex-rs/windows-sandbox-rs/src/setup.rssilently removes nonexistent roots.apply_legacy_session_acl_rulesinspawn_prep.rssuppresses several allow/deny ACL errors, and the setup helper logs missing write roots as skipped.Reproduction detail
A named Add File probe succeeded once in the isolated official-source checkout. The immediately following built-in
apply_patchDelete File operation failed during sandbox preparation with the split-root diagnostic, before reading the probe. Shell and Git access continuing to work does not disprove this because those operations use a different launch path.Proposed enforcement contract
A complete launcher/policy fix should:
Windows CI should cover same-drive and cross-drive roots, spaces and Unicode, UNC, junction/reparse containment, alias deduplication, invalid-root partial failure and cleanup, shell plus built-in
apply_patchwrites in every declared root, and outside-root denial.This is a root-cause analysis and proposed acceptance contract, not a claim that the platform fix has been implemented or validated.