Skip to content

apply_patch fails on Windows with multiple writable roots #34970

Open

Description

@aniketp166

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

Version 26.715.72359

What subscription do you have?

Pro

What platform is your computer?

Microsoft Windows NT 10.0.26200.0 x64

What issue are you seeing?

On Windows, apply_patch fails before it opens any workspace file.

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

The task is launched with two writable roots:

I uninstalled the Visualize plugin and restarted both the laptop and Codex, but new Codex tasks still receive the visualization writable root. This prevents apply_patch from editing any file.

Expected: apply_patch should work in a normal local project task, or Codex should not attach the stale visualization root.

What steps can reproduce the bug?

  1. Open the Codex desktop app on Windows.
  2. Open a local project task in
  3. Ask Codex to make any small file edit using apply_patch.
  4. The task environment includes the project root plus a .codex\visualizations...\ directory as writable roots.
  5. apply_patch fails before reading or modifying the target file.

I also uninstalled the Visualize plugin and restarted both Codex and Windows. New tasks still get the extra visualization writable root and reproduce the same failure.

What is the expected behavior?

No response

Additional information

No response

Activity

  1. added
    app
    on Jul 23, 2026
  2. added
    bug
    windows-os
    sandbox
    on Jul 23, 2026
  3. github-actions commented on Jul 23, 2026

    @github-actions
    Contributor

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

    Powered by Codex Action

  4. Loumeister commented on Aug 24, 2026

    @Loumeister

    I can reproduce a distinct elevated-sandbox variant of this bug on Windows Codex Desktop. The CLI installed alongside it reports codex-cli 0.146.0.

    The effective permission graph includes:

    • writable: C:\Users\<user>
    • protected/read-only: C:\Users\<user>\.codex
    • writable again: C:\Users\<user>\.codex\visualizations\<date>\<thread>
    • the actual repository as another writable root

    Every command spawn then fails before the command runs with:

    windows elevated sandbox cannot reopen writable descendants under read-only carveouts directly; refusing to run unsandboxed
    

    A fresh CLI run constrained to the exact repository with --sandbox workspace-write --cd <repo> succeeds. That indicates the repository ACLs are not the cause; Desktop is emitting an impossible writable-parent / protected-child / reopened-writable-descendant root graph.

    User impact

    This has turned into an almost six-hour troubleshooting task. The complete task's cumulative local counters at audit time show:

    • 32,572,578 total processed tokens
    • 31,385,472 cached input tokens
    • 1,043,896 non-cached input tokens
    • 143,210 output tokens, including 68,198 reasoning tokens

    I am not claiming that every one of those tokens is directly billable or solely attributable to this defect; cached and non-cached usage are accounted differently. The figures show the total scale of the troubleshooting task and its substantial credit/usage-limit impact.

    Separately, three specifically measured exact-repository workaround runs consumed 81,276 additional tokens outside the actual benchmark, including a 26,315-token failed child and a 35,417-token successful child. The fallback reloads task context, so every failed Desktop spawn can cause significant duplicated work.

    Please address both layers:

    1. Treat this exact elevated error as deterministic in Desktop: do not retry the same sandbox spawn; automatically continue once through an exact-repository workspace-write child and return its result to the original task.
    2. Fix the workspace-root producer so it does not grant a broad home ancestor together with a writable capability directory inside protected CODEX_HOME.

    The elevated backend's fail-closed behavior should remain intact; weakening the sandbox or using full access is not an acceptable fix.

    This is related to #34970 because the same visualization root is injected, but it is not the same refusal path: #34970 reports the unelevated split-root check, while this report reaches the elevated reopened-descendant check.

  5. zjbob commented on Sep 2, 2026

    @zjbob

    Retested the distinct elevated-sandbox variant on 2026-09-02. It remains reproducible in the current official Windows Desktop runtime:

    • Desktop: 26.831.1445.0
    • Bundled CLI: codex-cli 0.152.0
    • Platform: native Windows x64
    • Mode: managed workspace-write using the elevated Windows sandbox
    • Executable: official Desktop-bundled binary; no custom binary was used for this repro

    The effective permission graph contains an authorized writable descendant beneath a protected directory:

    <workspace>                  writable
    <workspace>\.agents         read-only
    <workspace>\.agents\sessions writable
    

    A built-in apply_patch operation against a task-owned scratch file inside the writable workspace fails before reading or modifying the target:

    windows elevated sandbox cannot reopen writable descendants under read-only carveouts directly; refusing to run unsandboxed
    

    The same profile can also prevent otherwise read-only command launches before the child process starts. This is not the older unelevated split-root refusal: the runtime explicitly selects the elevated backend and reaches the reopened-descendant check.

    The fail-closed behavior is correct; weakening the sandbox or silently running unsandboxed would not be. The missing behavior is a safe way to execute an already-authorized single-path filesystem request when the full permission graph contains a reopened writable descendant.

    A source-level prototype against rust-v0.151.0-alpha.7.2 validated one bounded approach:

    1. Validate the exact requested path against the original permission policy.
    2. Derive a request-scoped, non-overlapping capability root for that one filesystem operation.
    3. Disable symlink/reparse-point following on that compatibility path.
    4. Keep unsupported multi-path/discovery requests and arbitrary process execution fail-closed.
    5. Preserve the existing path on Linux, macOS, and Windows profiles without reopened writable descendants.

    Focused unit and Windows helper integration tests passed for ordinary writable files, the authorized reopened descendant, protected siblings, outside paths, and non-Windows compilation. This latest official-runtime reproduction shows the elevated variant still needs a runtime fix and regression coverage.

  6. zjbob commented on Oct 9, 2026

    @zjbob

    Additional reproducible elevated-backend evidence for this issue, from native Windows and VS Code extension 26.1007.21434 / bundled CLI 0.162.0-alpha.17.2.

    The failing policy is a writable scratch workspace, its protected/read-only .agents directory, and an explicitly reopened writable .agents/sessions descendant. With approvals disabled, ordinary exec_command reads fail before process creation:

    windows elevated sandbox cannot reopen writable descendants under read-only carveouts directly; refusing to run unsandboxed
    

    The exact official source tag is rust-v0.162.0-alpha.17.2, commit 740e5af33c71225640e0c1c1555c514c2c93ab74. resolve_windows_elevated_filesystem_overrides in codex-rs/sandboxing/src/windows.rs rejects this policy through has_reopened_writable_descendant before elevated setup can enforce the requested roots. The same check was still present in upstream main when inspected on 2026-10-09.

    A synthetic, local-only reproduction is available in my version-pinned toolkit. It drives actual CLI exec_command and native apply_patch through a loopback mock Responses server, so there is no model call or private repository payload:

    node scripts/windows-runtime/probe.mjs <absolute-official-codex.exe> <new-local-evidence-directory> reopened
    

    Use the complete matching official runtime directory, not a lone executable. The script creates disposable fixtures and includes both --ignore-user-config and --ignore-rules, elevated sandboxing, approvals never, and an explicit named permission profile. Ignoring user config alone is not sufficient: saved exec rules can approve unsandboxed execution and falsely make a shell test appear successful. Standalone codex sandbox is also not equivalent to this tool-dispatch path.

    I have a narrow local candidate fix plus regressions. It removes only the elevated blanket rejection while preserving original root projection and ancestor denies. The unelevated restricted-token rejection remains. It changes no production ACL masks or token setup. The rationale is that elevated setup grants explicit writable-root allows, which take precedence over inherited ancestor denies; ancestor/sibling restrictions still need to be verified separately.

    Observed validation:

    • Untouched official reopened-root control reproduces the failure; ordinary-workspace control passes.
    • All 59 sandbox transformation unit tests and an integration regression using the actual elevated sandbox account pass with the candidate.
    • Rebuilt CLI with matching official unchanged setup/runner helpers passes four 27-case matrices: ordinary, reopened/network-enabled, reopened/network-restricted, and a disposable linked worktree.
    • Cases cover shell reads/writes/deletes, native patch add/update/hunk-delete/move/whole-file-delete, independent readbacks, and denied protected sibling write/delete, ancestor rename, outside write/delete, traversal, and junction escape. Protected/outside fixture contents remain unchanged.
    • A fresh VS Code session after reload confirms default-permission shell reads and native patch lifecycle operations in both the workspace and reopened descendant.

    This is a proposed implementation with evidence for the tested layouts, not a claim that removing guards is generally safe for every Windows policy. Please evaluate whether the elevated backend can support this explicit descendant grant, or whether the host should avoid generating an unsupported policy. I am sharing the reproduction and analysis here in accordance with the current contribution policy; no external PR is being opened.

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