Skip to content

Windows Desktop sandbox forces choice between CreateProcessAsUserW 1312 and apply_patch split-root failure #31220

Open

Description

@martinmclee

What version of the Codex App are you using (From "About Codex" dialog)?

26.623.13972.0

Desktop package:

OpenAI.Codex_26.623.13972.0_x64__2p2nqsd0c76g0

Codex CLI/runtime:

codex-cli 0.142.5

What subscription do you have?

Pro 5x

What platform is your computer?

Windows 11 Home 25H2, 64-bit, build 26200.8655.

Registry version fields:

ProductName        : Windows 10 Home
DisplayVersion     : 25H2
CurrentBuild       : 26200
CurrentBuildNumber : 26200
UBR                : 8655
EditionID          : Core
InstallationType   : Client

Codex environment also reported:

Microsoft Windows NT 10.0.26200.0 x64

Note: Windows compatibility APIs still report ProductName = Windows 10 Home
and NT version 10.0, but the 25H2 display version and 26200 build identify
this as a Windows 11 system.

Shell: PowerShell

What issue are you seeing?

Codex Desktop on Windows currently forces a choice between two broken sandbox
configurations:

  1. With [windows] sandbox = "unelevated":

    • normal shell commands work
    • apply_patch can create files
    • apply_patch update/delete fails before patching workspace files
  2. With [windows] sandbox = "elevated":

    • apply_patch create/update/delete works
    • normal shell commands fail before PowerShell starts

So there does not appear to be a working Windows Desktop setup where both safe
file edits and ordinary diagnostic/build/test commands work in the same session.

This looks related to both existing issues:

Current relevant config for the latest repro:

approval_policy = "never"
sandbox_mode = "danger-full-access"

[windows]
sandbox = "elevated"

Observed with [windows] sandbox = "elevated":

windows sandbox: runner error: CreateProcessAsUserW failed: 1312

This happens even for simple read-only commands.

Observed with [windows] sandbox = "unelevated":

apply_patch verification failed: Failed to read file to update <workspace file>:
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

What steps can reproduce the bug?

  1. Use Codex Desktop on Windows with a normal managed workspace-write session.
  2. Set:
[windows]
sandbox = "unelevated"
  1. Restart Codex Desktop.
  2. In a workspace, run a normal shell command such as Get-Location.
  3. Observe that shell commands work.
  4. Use apply_patch to create a new file.
  5. Observe that file creation works.
  6. Use apply_patch to update or delete an existing workspace file.
  7. Observe that apply_patch fails with:
windows unelevated restricted-token sandbox cannot enforce split writable root sets directly; refusing to run unsandboxed
  1. Change config to:
[windows]
sandbox = "elevated"
  1. Restart Codex Desktop.
  2. Use apply_patch to create/update/delete a workspace file.
  3. Observe that apply_patch works.
  4. Run a simple shell command such as Get-Location, codex --version, or a
    file read command.
  5. Observe that shell execution fails before PowerShell starts with:
windows sandbox: runner error: CreateProcessAsUserW failed: 1312

What is the expected behavior?

There should be at least one Windows Desktop sandbox configuration where both of
these are true:

  • apply_patch can create/update/delete files inside the active workspace root.
  • ordinary shell commands can run for diagnostics/build/test operations.

If the unelevated Windows sandbox cannot enforce split writable root sets, Codex
Desktop should avoid injecting a sandbox shape that breaks apply_patch, or
apply_patch should use a sandbox strategy that supports the Desktop-managed
profile.

If the elevated Windows sandbox is the intended workaround for apply_patch,
ordinary shell commands should still launch successfully instead of failing with
CreateProcessAsUserW failed: 1312.

Additional information

Troubleshooting already tried without resolving the issue:

  1. Changed [windows] sandbox to unelevated.

    • Result: shell commands worked, but apply_patch update/delete failed with
      the split writable roots error.
  2. Changed [windows] sandbox back to elevated.

    • Result: apply_patch worked, but normal shell commands failed with
      CreateProcessAsUserW failed: 1312.
  3. Restarted Codex Desktop after config changes.

    • Result: no change.
  4. Ended older Codex tasks/processes and restarted Codex again.

    • Result: no change.
  5. Tried launching/restarting Codex "as administrator".

    • Result: process token checks still reported Codex processes as not elevated
      (Elevated=0), and shell commands still failed in elevated sandbox mode.
  6. Tried:

[windows]
sandbox = "elevated"
sandbox_private_desktop = false
  • Result: normal shell commands still failed with
    CreateProcessAsUserW failed: 1312.
  1. Tried excluding temp writable roots:
[sandbox_workspace_write]
exclude_tmpdir_env_var = true
exclude_slash_tmp = true
  • Result: the Desktop managed permission profile still exposed extra writable
    roots such as C:\tmp; apply_patch still failed in unelevated mode.
  1. Tried a custom permission profile with only the workspace root writable.

    • Result: the config parsed and a direct codex sandbox -P <profile> ...
      check worked, but Desktop managed sessions still injected the extra
      writable roots, so app session behavior did not change.
  2. Tried direct elevated launch attempts for the packaged app:

    • Direct Start-Process against the WindowsApps package executable failed
      with access denied due to package ACLs.
    • Start-Process via shell:AppsFolder\OpenAI.Codex_2p2nqsd0c76g0!App
      returned success but appeared to focus/reuse the existing non-elevated app
      instance instead of starting an elevated Codex process.
  3. Rechecked after explicitly ending old Codex tasks and restarting as admin.

    • Result: current Codex process token checks still showed Elevated=0.

The report intentionally redacts the local user profile and workspace paths.

Activity

  1. added
    bug
    app
    windows-os
    sandbox
    tool-calls
    on Jul 6, 2026
  2. pellorao commented on Jul 10, 2026

    @pellorao

    I can reproduce the same unelevated sandbox failure with Codex CLI v0.144.1 on Windows.

    Configuration:

    [windows]
    sandbox = "unelevated"

    The session uses workspace-write. I have no [sandbox_workspace_write] section and no user-configured writable_roots.

    apply_patch fails with:

    windows unelevated restricted-token sandbox cannot enforce split writable root sets directly
    

    Runtime diagnostics show the workspace plus runtime-managed special temp roots such as :special slash_tmp and :special tmpdir.

    I also tried setting both TEMP and TMP to a directory inside the workspace before launching Codex, but the failure remained. This suggests that the special temp-root representation itself still causes a split writable-root set.

    Codex CLI v0.142.5 with the unelevated sandbox previously allowed apply_patch on the same machine, so this may also be a regression affecting v0.144.1.

  3. bhayden1 commented on Jul 14, 2026

    @bhayden1

    Additional reproduction from Codex Desktop on Windows 10 Home:

    • Desktop runtime reported in-session: 26.707.72221.
    • The desktop permission UI was set to Full access, but the effective task context still reported sandbox_mode = "workspace-write" and invoked the unelevated Windows sandbox wrapper.
    • The managed session included multiple writable roots: the workspace, C:\tmp, and a Codex visualization directory.
    • Updating an existing workspace file via apply_patch failed before reading the target:
    apply_patch verification failed: Failed to read file to update <workspace>\src\deckTests\ggo.test.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
    
    • Switching from elevated to unelevated had been suggested after elevated mode caused failures, so neither configuration has provided a reliable editing workflow.
    • Reinstalling the desktop app did not resolve the problem.

    The misleading Full access UI state is important: the patch path still behaved as sandboxed/unelevated in the active task.

  4. Saru-github commented on Jul 20, 2026

    @Saru-github

    Additional controlled A/B reproduction from Codex Desktop on Windows (2026-07-20). I originally posted this datapoint on #30009, but this issue appears to be the canonical tracker for the split-root Windows sandbox failure.

    Environment:

    • Codex Desktop: 26.715.4045.0
    • Windows: Microsoft Windows NT 10.0.26200.0 x64
    • Normal local Git workspace
    • Tiny temporary text file inside the workspace

    Managed workspace-write / restricted-filesystem mode:

    1. apply_patch Add File stalled for about 60 seconds.
    2. It eventually returned {}, and the file had been created correctly.
    3. A subsequent apply_patch Delete File was still unresponsive after about 20 seconds and the task was interrupted.
    4. The file remained after interruption.

    After changing only the task permission profile to danger-full-access / unrestricted in the same workspace:

    • Delete leftover file: 55 ms
    • Add file: 91 ms
    • Content verification: succeeded
    • Delete file: 413 ms
    • Final verification: file absent and no Git status residue

    This isolates the long stall/hang to the Windows restricted sandbox/wrapper path rather than patch parsing or the workspace filesystem.

    Original comment with the same measurements: #30009 (comment)

  5. ryrun commented on Sep 2, 2026

    @ryrun

    I can reproduce this outside the Codex Desktop app through Zed's ACP integration.

    Environment:

    • Windows 11 x64
    • codex-acp 1.8.0
    • bundled codex-cli 0.152.1
    • managed workspace-write profile
    • UNC workspace: \\<server>\<share>\<workspace>

    apply_patch can create new files, but updating existing files fails with:

    windows unelevated restricted-token sandbox cannot enforce split writable root sets directly; refusing to run unsandboxed
    

    Session logs show that apply_patch worked on the same UNC workspace with Codex 0.142.4. The failure appeared with 0.145.0 and remains reproducible with 0.152.1.

    This appears to be the same CLI/runtime issue as #32168, but it is also reproducible when Codex is hosted through ACP, without using the Desktop app.

    #35864 seems to be a related fix.

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

    appbugsandboxtool-callswindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions