Skip to content

Windows sandbox initialization fails with "setup refresh failed with status exit code: 1" #24416

Open

Description

@jiabirc6

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

  1. added
    bug
    app
    windows-os
    sandbox
    on May 25, 2026
  2. github-actions commented on May 25, 2026

    @github-actions
    Contributor
  3. warren2008-2020-spec commented on Jul 16, 2026

    @warren2008-2020-spec

    I published a small read-only diagnostic CLI for Codex setup issues that might be useful when collecting environment information for Windows sandbox failures:

    npx --yes codex-doctor

    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:

    • Windows/WSL platform state
    • Node and npm availability/auth
    • Git and GitHub CLI availability/auth
    • Codex CLI availability
    • Codex config presence and WSL-mode hints
    • proxy / NO_PROXY hints
    • CI environment hints

    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.

  4. tiwat-lim commented on Sep 12, 2026

    @tiwat-lim

    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.

  5. liudenghui63-stack commented on Sep 12, 2026

    @liudenghui63-stack

    Confirming this exact .sandbox-bin failure 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

    • Windows 11 Home, Chinese edition, x64
    • OS version/build: 10.0.26200 / 26200
    • Microsoft Store/MSIX package: OpenAI.Codex 26.908.4834.0
    • Package family: OpenAI.Codex_2p2nqsd0c76g0
    • Sandbox setup marker version: 5
    • Native/elevated Windows sandbox

    All 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:

    • reinstalling Codex;
    • rebooting Windows;
    • resetting the app;
    • clearing Codex user state;
    • retrying setup several times.

    UAC itself was healthy: launching an elevated PowerShell produced the normal UAC prompt.

    Codex had partially completed provisioning. These files existed:

    %USERPROFILE%\.codex\.sandbox\setup_marker.json
    %USERPROFILE%\.codex\.sandbox\setup_error.json
    %USERPROFILE%\.codex\.sandbox\deny_read_acl_state.json
    

    The marker was valid JSON and named the expected sandbox users:

    {
      "version": 5,
      "offline_username": "CodexSandboxOffline",
      "online_username": "CodexSandboxOnline"
    }

    deny_read_acl_state.json was 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-bin was empty. Its DACL was protected/explicit-only, its owner was BUILTIN\Administrators, and its relevant ACEs were:

    <machine>\CodexSandboxUsers:(OI)(CI)(RX)
    NT AUTHORITY\SYSTEM:(OI)(CI)(M)
    BUILTIN\Administrators:(OI)(CI)(M)
    <machine>\<user>:(OI)(CI)(M)
    

    A non-elevated icacls attempt 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:

    $bin = Join-Path $env:USERPROFILE ".codex\.sandbox-bin"
    $me  = "$env:USERDOMAIN\$env:USERNAME"
    icacls $bin /grant:r "$($me):(OI)(CI)F" "BUILTIN\Administrators:(OI)(CI)F" "NT AUTHORITY\SYSTEM:(OI)(CI)F"

    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:

    helper_sandbox_lock_failed:
    lock sandbox bin dir C:\Users\<user>\.codex\.sandbox-bin failed:
    SetNamedSecurityInfoW sandbox dir failed: 5
    

    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:

    • owner: BUILTIN\Administrators
    • inheritance protected: True
    • real user: Modify, Synchronize
    • Administrators: Modify, Synchronize
    • SYSTEM: Modify, Synchronize
    • CodexSandboxUsers: ReadAndExecute, Synchronize
    • empty

    The live sandbox log recorded:

    setup error: helper_sandbox_lock_failed:
    lock sandbox bin dir C:\Users\<user>\.codex\.sandbox-bin failed:
    SetNamedSecurityInfoW sandbox dir failed: 5
    
    setup refresh: exited with status ExitStatus(ExitStatus(1))
    

    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:

    Owner: <machine>\<user>
    Inheritance protected: True
    
    SYSTEM:                 Modify, Synchronize
    Administrators:         Modify, Synchronize
    <user>:                 Modify, Synchronize
    CodexSandboxUsers:      ReadAndExecute, Synchronize
    

    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:

    setup refresh: processed 4 write roots (read roots delegated); errors=[]
    

    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:

    Modify             = 197055  (0x301BF)
    ChangePermissions  = 262144  (0x40000 / WRITE_DAC)
    FullControl        = 2032127 (0x1F01FF)
    

    Therefore Modify does not contain ChangePermissions/WRITE_DAC. Full Control does.

    The current open-source Windows setup implementation is also consistent with this failure mode:

    • lock_sandbox_bin_dir requests a protected DACL;
    • the real-user mask is FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_GENERIC_EXECUTE | DELETE, with no explicit WRITE_DAC;
    • the Full/Interactive/ReadAcls paths call SetNamedSecurityInfoW to replace the DACL;
    • the newer ProvisionOnly path explicitly opens a directory handle with 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:

    1. an elevated setup path creates or leaves .sandbox-bin owned by Administrators;
    2. Codex writes a protected DACL granting the real user only generic Modify;
    3. a later non-elevated refresh tries to replace that DACL;
    4. the real user is neither owner nor explicitly granted WRITE_DAC;
    5. SetNamedSecurityInfoW returns 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    appbugsandboxwindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions