Repository navigation
Description
Bug Description
Codex desktop app on Windows fails to initialize the sandbox component, causing intermittent command execution failures. The error message is:
windows sandbox: setup refresh failed with status exit code: 1
Steps to Reproduce
Open Codex desktop app on Windows
Try to execute any shell command or use the js_repl tool
Observe that commands fail with the sandbox initialization error
Occasionally commands succeed, but failure rate is very high (~80-90%)
Expected Behavior
Shell commands and js_repl should execute reliably without sandbox initialization failures.
Actual Behavior
Shell commands fail with: Io(Custom { kind: Other, error: "windows sandbox: setup refresh failed with status exit code: 1" })
js_repl fails with: node_repl kernel exited unexpectedly ... windows sandbox failed: setup refresh failed with status exit code: 1
The error is intermittent - sometimes commands succeed, but most fail
Environment
OS: Windows (Chinese edition)
Codex Desktop App (latest version)
Node.js installed at: D:\nodejs
npm global prefix: D:\npm-global
Workspace: D:\codex
Config File (D:\codex-config\config.toml)
[sandbox]
mode = "danger-full-access"
sandbox.log Content
failed: SetNamedSecurityInfoW sandbox dir failed: 5
[2026-05-25 14:13:15.845 codex-windows-sandbox-setup.exe] setup error: helper_sandbox_lock_failed: lock sandbox bin dir C:\Users\Administrator.codex.sandbox-bin failed: SetNamedSecurityInfoW sandbox dir failed: 5
[2026-05-25 14:13:15.854 codex.exe] setup refresh: exited with status ExitStatus(ExitStatus(1))
Additional Context
Error code 5 in SetNamedSecurityInfoW is ERROR_ACCESS_DENIED
Setting mode = "danger-full-access" in config.toml does not resolve the issue
The sandbox setup binary (codex-windows-sandbox-setup.exe) appears to have permission issues accessing C:\Users\Administrator.codex.sandbox-bin
This makes the Codex desktop app nearly unusable on Windows as most operations require shell execution
Suggested Investigation
Check if codex-windows-sandbox-setup.exe has proper permissions to modify sandbox directories
Investigate why SetNamedSecurityInfoW fails with access denied
Consider providing a way to completely bypass sandbox setup on Windows
The danger-full-access mode should ideally skip sandbox initialization entirely
Activity
github-actions commentedon May 25, 2026
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
warren2008-2020-spec commentedon Jul 16, 2026
I published a small read-only diagnostic CLI for Codex setup issues that might be useful when collecting environment information for Windows sandbox failures:
Repo: https://github.com/warren2008-2020-spec/codex-doctor
npm: https://www.npmjs.com/package/codex-doctor
It does not modify Codex or the sandbox. It only reports local signals such as:
For issues like this one, my intent is to make it easier to paste a safe setup report without exposing tokens or private config. If there are specific Windows sandbox checks that would help triage this failure mode, I can add them.
tiwat-lim commentedon Sep 12, 2026
I hit the same helper_sandbox_lock_failed error:
lock sandbox bin dir C:\Users\Admin.codex.sandbox-bin failed: SetNamedSecurityInfoW sandbox dir failed: 5
What fixed it for me was temporarily re-enabling ACL inheritance on the sandbox-bin directory from an elevated PowerShell:
icacls "$env:USERPROFILE.codex.sandbox-bin" /inheritance:e
After that I restarted Codex and ran the Windows setup again. The setup completed successfully.
Interestingly, after setup completed, icacls showed that Codex had removed inheritance again and restored its own explicit ACLs, so it looks like the installer/setup process needed inheritance enabled temporarily in order to successfully rewrite/lock the directory ACL.
Before the fix, the directory ACL was explicit-only and the setup repeatedly failed with Win32 error 5 (ERROR_ACCESS_DENIED).
This may indicate a migration/setup bug where .sandbox-bin can be left in a security state that prevents the helper from applying its final security descriptor.
liudenghui63-stack commentedon Sep 12, 2026
Confirming this exact
.sandbox-binfailure on a fresh Windows 11 machine, with a full before/after timeline and a second recurrence after the desktop UI had already become usable.Environment
OpenAI.Codex 26.908.4834.0OpenAI.Codex_2p2nqsd0c76g0All user and machine names below are redacted.
Phase 1: first-run setup could not finish
On a fresh Windows machine, the official Codex desktop app reached Finish Windows setup. Clicking Retry Windows setup repeatedly failed.
The following did not help:
UAC itself was healthy: launching an elevated PowerShell produced the normal UAC prompt.
Codex had partially completed provisioning. These files existed:
The marker was valid JSON and named the expected sandbox users:
{ "version": 5, "offline_username": "CodexSandboxOffline", "online_username": "CodexSandboxOnline" }deny_read_acl_state.jsonwas also valid JSON:{ "principals": {} }It was not corrupted and did not contain NUL bytes.
The exact setup error was:
{ "code": "helper_sandbox_lock_failed", "message": "lock sandbox bin dir C:\\Users\\<user>\\.codex\\.sandbox-bin failed: SetNamedSecurityInfoW sandbox dir failed: 5" }Before the first workaround,
%USERPROFILE%\.codex\.sandbox-binwas empty. Its DACL was protected/explicit-only, its owner wasBUILTIN\Administrators, and its relevant ACEs were:A non-elevated
icaclsattempt failed with Access Denied.First workaround
From an elevated PowerShell, Full Control was temporarily granted on only this Codex-owned directory to the real user, Administrators, and SYSTEM:
After closing the elevated shell, restarting Codex normally, and clicking Retry Windows setup, setup completed and the desktop UI opened.
Phase 2: the same failure returned inside the working desktop app
After entering the desktop app, a new Codex task attempted a simple read-only PowerShell command. Every sandboxed command failed before PowerShell started, with the same error:
The same read-only command worked immediately outside the sandbox, so the file and PowerShell were not the problem.
A read-only ACL inspection showed that Codex setup had restored the protected DACL and the
(M)entries. The directory was again:BUILTIN\AdministratorsTrueModify, SynchronizeModify, SynchronizeModify, SynchronizeReadAndExecute, SynchronizeThe live sandbox log recorded:
This shows why granting Full Control was sufficient to finish first-run setup but was not durable when the owner remained Administrators: setup replaced the DACL with the intended Modify-based ACL, after which the next non-elevated refresh could no longer replace it again.
Second workaround and persistent result
The empty failing directory was moved aside as a backup, then recreated by the normal user. This changed the owner to the real user without changing global Windows security or the Codex configuration.
The next normal sandbox refresh succeeded, created the signed command runner in
.sandbox-bin, and Codex then reapplied its protected explicit DACL.Crucially, after refresh:
So the final DACL is again the Codex-intended Modify-based ACL, but the directory owner remains the real user. Multiple subsequent fresh sandbox processes/refreshes succeeded. The log currently contains at least eight consecutive entries like:
The original Admin-owned, protected, empty directory was retained as a backup for comparison.
Why Modify fails while Full Control or user ownership succeeds
On this machine, the .NET masks are:
Therefore
Modifydoes not containChangePermissions/WRITE_DAC. Full Control does.The current open-source Windows setup implementation is also consistent with this failure mode:
lock_sandbox_bin_dirrequests a protected DACL;FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_GENERIC_EXECUTE | DELETE, with no explicitWRITE_DAC;SetNamedSecurityInfoWto replace the DACL;READ_CONTROL | WRITE_DAC.Source: https://github.com/openai/codex/blob/main/codex-rs/windows-sandbox-rs/src/bin/setup_main/win.rs
Observed facts therefore support an ownership/ACL lifecycle or idempotence bug:
.sandbox-binowned by Administrators;SetNamedSecurityInfoWreturns error 5.The successful owner-based repair is particularly useful evidence: after Codex restored the same protected Modify ACL, refreshes continued to work because the owner was now the real user.
This is a diagnosis from the observed ACL transition and current source; it is not a claim that every report with error 5 has the same target or cause.
Security scope
Neither workaround disabled UAC or Defender, changed registry/EFS settings, changed
WindowsApps, or granted access outside%USERPROFILE%\.codex\.sandbox-bin.A product fix should make the directory ownership/DACL transition internally consistent and idempotent, or ensure the later refresh has the required WRITE_DAC capability, rather than requiring users to repair this directory manually.