Windows sandbox: CreateProcessAsUserW fails with error 5 when the resolved shell is the MSIX (Store) build of pwsh
Summary
On Windows, the sandbox fails with CreateProcessAsUserW failed: 5 (Access is denied.) whenever the resolved shell is the MSIX (Microsoft Store) build of PowerShell 7. Windows refuses to launch a packaged (MSIX) binary under the restricted token the sandbox creates.
This appears to be the underlying cause behind several open reports (openai/codex#26803, openai/codex#25436, openai/codex#26186, #10090, openai/codex#9062, and likely openai/codex#30047 / openai/codex#26896 where accounts were also involved). None of them identify the packaged-shell condition, which is why the failure looks environment-specific and unreproducible: it depends solely on whether pwsh resolves to C:\Program Files\WindowsApps\....
Measurement
Same machine, same session, 20 trials per shell. Counted on the presence of CreateProcessAsUserW in the output, not on the exit code (cmd.exe legitimately returns non-zero, which is misleading).
| shell launched by the sandbox | failures |
|---|---|
pwsh.exe — Store/MSIX (C:\Program Files\WindowsApps\Microsoft.PowerShell_7.6.4.0_x64__8wekyb3d8bbwe\pwsh.exe) |
20 / 20 |
powershell.exe 5.1 (C:\Windows\System32\WindowsPowerShell\v1.0\) |
0 / 20 |
cmd.exe |
0 / 20 |
| git bash | 0 / 20 |
End-to-end confirmation: codex exec with the normal PATH resolves the MSIX pwsh and fails. The same codex exec with the WindowsApps entries removed from PATH falls back to PowerShell 5.1 and returns normally (exit 0, ~720 ms).
Error payload
windows sandbox: runner failed during SpawnChild: CreateProcessAsUserW failed: 5 (Access is denied.)
| cwd=C:\Users\<user>\<workspace>
| cmd="C:\Program Files\WindowsApps\Microsoft.PowerShell_7.6.4.0_x64__8wekyb3d8bbwe\pwsh.exe" -NoProfile -Command "..."
| env_u16_len=6928 | si_flags=256 | creation_flags=525312 (Windows error 5)
creation_flags=525312 = 0x80400 = CREATE_UNICODE_ENVIRONMENT | EXTENDED_STARTUPINFO_PRESENT.
Two red herrings we eliminated, in case they save someone time
- Environment block size.
env_u16_len=6928is constant across all 20 failures, and it is ~5× below the documented 32,767 limit. An oversized block would also raiseERROR_INVALID_PARAMETER(87), not 5. Not the cause. - "Intermittent" behaviour. It looks intermittent but is deterministic per command: in our environment
echo hellofailed 20/20 whileGet-Content <path>succeeded 20/20 — file reads evidently take a path that never reachesSpawnChild. Observers who tested different commands drew opposite conclusions from the same broken setup.
Also ruled out on this machine: the CodexSandboxOffline / CodexSandboxOnline accounts both exist and are enabled, so this is not the missing-account variant.
Environment
- Windows 11 Pro, 10.0.26200
codex-cli0.144.3~/.codex/config.toml:[windows] sandbox = "elevated"
Suggested fix
When resolving the shell, skip binaries under %ProgramFiles%\WindowsApps (or any MSIX-packaged executable) and fall back to System32\WindowsPowerShell\v1.0\powershell.exe. A packaged binary cannot be started under a restricted token, so it can never work on the sandbox path.
A clear error message would help too — Access is denied gives no hint that the shell is the problem.
Workarounds for anyone hitting this now
- Ensure a non-packaged
pwshprecedes the Store one inPATH, or removeWindowsAppsfrom thePATHhanded to codex. [windows] sandbox = "unelevated"in~/.codex/config.toml(documented fallback; not needed once the shell is non-packaged).
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
- #34872
Powered by Codex Action
Correction / refinement to the report above: there are two independent variables, not one. Further measurement shows the MSIX shell alone is not sufficient — the failure requires elevated mode AND an MSIX-packaged target. Changing either one fixes it.
Same machine, same MSIX pwsh target, 20 trials each:
| sandbox mode | failures |
|---|---|
windows.sandbox=elevated (our config) |
20 / 20 |
windows.sandbox=unelevated |
0 / 20 |
End-to-end with a real model turn:
codex exec -c windows.sandbox="unelevated" "git log -1 --oneline" → succeeded in 813 ms
So the accurate statement is: under elevated mode, the sandbox cannot launch an MSIX-packaged binary under its restricted token. Under unelevated, the same packaged shell launches fine.
This is worth knowing for triage, because it means affected users have two independent escapes — avoid the packaged shell, or switch the mode — and it may explain why some reporters see the failure and others with Store PowerShell do not: their mode differs.
Also: the "which commands fail" boundary is now precise
The earlier note about apparent intermittency resolves cleanly. In our runtime, simple readable operations are served internally and never reach SpawnChild; anything else attempts a real spawn and fails 100% of the time.
| command | failures |
|---|---|
Get-Content <file> |
0 / 5 |
Get-ChildItem |
0 / 5 |
Get-Content <file> | Measure-Object |
5 / 5 |
$PSVersionTable.PSVersion |
5 / 5 |
A pipe, or any non-read command, is enough to cross into the failing path. This is almost certainly why the same broken setup produces contradictory reports from different users depending on which command they happened to try first.
Important caveat on the unelevated workaround I listed above — it is a degradation, not an equivalent fix. We measured what it costs before adopting it, and then rejected it. Posting the numbers so nobody takes it as a clean escape.
Two measured costs of running windows.sandbox=unelevated:
- PowerShell drops to ConstrainedLanguage mode (verified twice, 5/5 each). Any .NET method call,
Add-Type, or type cast fails inside an agent script. - The read-only sandbox tier is not available. The codex binary states it plainly: "Restricted read-only access requires the elevated Windows sandbox backend". If your workflow relies on read-only agents,
unelevatedsilently weakens them — a deny-read on a sensitive file becomes a no-op. OpenAI's own documentation also notes the non-admin mode "carries greater risk if prompt injected".
There is also a footgun worth flagging on its own: codex app-server silently tolerates unknown -c keys (measured). A configuration-based workaround therefore fails silently if the key is ever renamed upstream — the failure comes back with no signal at all.
So the accurate framing is:
- avoiding the MSIX shell is a genuine fix (the sandbox backend is unchanged);
- switching to
unelevatedis a workaround that degrades the security backend, acceptable only if you don't depend on the read-only tier or on full-language PowerShell.
What we'd actually like from upstream: that the elevated backend be able to launch an MSIX-packaged binary, or — failing that — that it refuse the packaged shell explicitly and fall back to System32\WindowsPowerShell\v1.0\powershell.exe, with an error message naming the shell as the cause. Access is denied sends everyone hunting through account SIDs and permissions, which is where the seven existing reports went.
For the record, the fix we shipped on our side keeps elevated and removes the WindowsApps directories from the PATH of the child process we spawn — narrow, logged by name, and it leaves the sandbox backend intact.
Independent confirmation from Codex Desktop on Windows (sanitized; user authorized sharing).
Environment:
- Codex Desktop
26.721.4979.0 - Windows
Microsoft Windows NT 10.0.26200.0 - command runner
0.146.0-alpha.3.1 - managed
workspace-writesession
Observed on 2026-07-29 while running a read-only rg verification:
runner failed during SpawnChild: CreateProcessAsUserW failed: 5 (Access denied.)
| cmd=C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\pwsh.exe -NoProfile -Command "..."
| si_flags=256 | creation_flags=525312 (Windows error 5)
The command did not start. Retrying the same verification with the shell explicitly set to:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
succeeded immediately (exit 0). This matches the packaged/WindowsApps PowerShell resolution condition described in this issue and provides a current Desktop-app reproduction. No credentials, customer data, or private workspace paths are included here.
Follow-up from the same sanitized Codex Desktop environment reported above (user authorized sharing).
During a longer implementation turn on 2026-07-29, the default command runner hit the same failure again on multiple independent calls, including:
- an
rg ... | Select-Objectread-only inspection; - a simple
Get-Date -Format ...call.
Both failed before command execution with:
windows sandbox: runner failed during SpawnChild: CreateProcessAsUserW failed: 5 (Access denied.)
cmd=C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\pwsh.exe -NoProfile -Command "..."
si_flags=256 | creation_flags=525312 (Windows error 5)
Immediately retrying through C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe succeeded (exit 0) in each case. This confirms that the failure persists across repeated tool calls in the same Desktop session and is not specific to one repository command or pipeline. No credentials, customer data, or private workspace paths are included.
Not a duplicate of #34872 — different failing mechanism.
#34872 is about Node canonicalizing absolute paths at startup and hitting EPERM on lstat of workspace ancestors: a path-traversal / directory-access problem, where the fix is about which directories the sandbox grants.
This issue is about process creation: under windows.sandbox=elevated, CreateProcessAsUserW returns error 5 when the target binary is MSIX-packaged, before any command runs. It reproduces on a target that lives inside the workspace, with no ancestor traversal involved, and it disappears by changing either the mode or the binary — neither of which is a path-permission change.
Same platform and same subsystem, but the failing step and the fix differ. Keeping this one open.
@ffonsecabc — thank you for the independent confirmation, and for the second follow-up. Two details from your reports are worth pinning down for triage:
- the failing target is the WindowsApps alias
pwsh.exe(an MSIX execution alias), and the immediate retry through the inboxSystem32\WindowsPowerShell\v1.0\powershell.exesucceeds — which matches the packaged-vs-unpackaged boundary measured above; - it recurs across independent calls in one session, including trivially read-only ones (
Get-Date), so it is not workload-dependent.
That is a second environment, on a different Codex build, showing the same boundary.
Additional Codex Desktop reproduction on Windows.
Environment
- Codex Desktop version:
26.721.41059 - Workspace: trivial empty folder at
C:\temp\codextest - Workspace sandbox permission: Read only
- Tested with both:
[windows] sandbox = "elevated"[windows] sandbox = "unelevated"
Direct invocation failures
Direct PowerShell commands such as:
Get-Location
git --version
both fail with:
CreateProcessAsUserW failed: 5 (Access is denied.)
This reproduces under both elevated and unelevated; changing the sandbox setting did not alter the result.
Control cases that succeed
cmd.exe /c git --version
returns:
git version 2.54.0.windows.1
and:
cmd.exe /c powershell -NoProfile -Command "Get-Location"
returns:
Path
----
C:\temp\codextest
So on this machine:
- PowerShell itself is executable inside the Codex security context.
cmd.exeworks.cmd.execan successfully launch PowerShell.- Only Codex Desktop's direct PowerShell spawn path fails with
CreateProcessAsUserWerror 5. - The problem is not specific to the repository or workspace ACLs.
This may be the same packaged-shell resolution defect described here, but the unelevated workaround does not resolve it in Codex Desktop version 26.721.41059. A practical current workaround is to retry commands through cmd.exe /c, including cmd.exe /c powershell -NoProfile -Command "...", rather than treating the direct PowerShell failure as complete shell unavailability.
Follow-up from the same Codex Desktop reproduction:
cmd.exe /c where pwsh
returns:
C:\Users\antho\AppData\Local\Microsoft\WindowsApps\pwsh.exe
while:
cmd.exe /c where powershell
returns:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
The Codex-injected PATH includes C:\Users\antho\AppData\Local\Microsoft\WindowsApps, after the Windows PowerShell 5.1 directory. The direct runner nevertheless appears to resolve pwsh, which lands on the WindowsApps alias, while the explicit workaround cmd.exe /c powershell -NoProfile -Command "Get-Location" succeeds through PowerShell 5.1.
This strongly aligns the Desktop case with the packaged/MSIX pwsh resolution cause described in this issue. One nuance: [windows] sandbox = "unelevated" still did not fix direct invocation in Codex Desktop 26.721.41059.
I traced the default Windows shell-selection path on current main. get_shell_path() accepts the which::which("pwsh") result before consulting the existing unpackaged PowerShell fallbacks. This means a WindowsApps/App Execution Alias can win even when C:\Program Files\PowerShell\7\pwsh.exe or Windows PowerShell 5.1 is available.
That appears consistent with the reproductions here. I would not assume the correct fix layer yet, though: shell detection is shared, whereas the incompatibility appears specific to the Windows sandbox spawn path. Would you prefer rejecting packaged candidates during default shell selection, or validating them at the elevated sandbox boundary so non-sandboxed Store PowerShell remains unaffected?
If you would like this addressed as an external contribution, please explicitly invite me to submit the focused fix and regression coverage.
Independent confirmation from Codex Desktop on Windows x64.
Environment
- Codex Desktop:
26.730.61639(MSIX package26.730.8199.0) - bundled codex runtime:
0.147.0-alpha.1.2 - Windows 11:
10.0.26200 - sandbox:
[windows] sandbox = "elevated" - PowerShell:
7.6.4
Reproduction
With the Microsoft Store/MSIX build of PowerShell 7 installed, the shell selected by Codex was the user-scoped app execution alias:
C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\pwsh.exe
PowerShell itself resolved to the packaged binary:
C:\Program Files\WindowsApps\Microsoft.PowerShell_7.6.4.0_x64__8wekyb3d8bbwe\pwsh.exe
Every sandboxed shell command failed before command execution:
windows sandbox: runner failed during SpawnChild:
CreateProcessAsUserW failed: 5 (Access is denied.)
The following were verified and did not resolve it:
CodexSandboxOfflineandCodexSandboxOnlineexisted and were enabled.- Sandbox setup completed and the copied
codex-command-runnerlaunched. - No domain or local computer GPO was applied.
- Trusting the Desktop executables and copied command runner in endpoint protection did not change the result.
- The same PowerShell command succeeded outside the Codex sandbox.
A/B confirmation
Installing the machine-wide MSI/WinGet build of the same PowerShell version changed resolution to:
C:\Program Files\PowerShell\7\pwsh.exe
After restarting Codex, the same command immediately succeeded inside the elevated sandbox:
CODEX_SANDBOX_OK
PowerShell=7.6.4
Executable=C:\Program Files\PowerShell\7\pwsh.exe
exit=0
This strongly confirms that Codex should detect and skip a user-scoped/MSIX pwsh.exe when using the Windows sandbox, fall back to a machine-wide shell, and surface an actionable error instead of generic Win32 error 5.
Reproduced a matching failure in Codex Desktop on Windows (2026-08-06): spawned subagents consistently fail before any command executes with CreateProcessAsUserW failed: 5 (Access is denied.), including Get-Location, Get-Content, and rg. The root agent in the same workspace can run the same commands normally.
The agent failure attempted the MSIX/WindowsApps pwsh.exe path. This is therefore a strong duplicate/corroborating report for the restricted-token packaged-shell cause described here.
I originally opened #37259 before finding this issue; closing it as duplicate.
I can reproduce this issue in Codex Desktop on Windows, and I have some additional diagnostics that may help.
Environment:
- Codex Desktop AppX: OpenAI.Codex_26.803.10989.0_x64__2p2nqsd0c76g0
- PowerShell 7.6.4 installed from Microsoft Store / MSIX
- sandbox_mode = "workspace-write"
- approval_policy = "on-request"
- approvals_reviewer = "auto_review"
- Auto-review enabled
- Full Access disabled
Failure: Every agent shell command inside the workspace fails before the command itself starts with:
CreateProcessAsUserW failed: 5 (Access is denied.)
Minimal reproducer:
Get-Content .\package.json -TotalCount 1
The sandbox log shows that the actual launcher is:
C:\Users<user>\AppData\Local\Microsoft\WindowsApps\pwsh.exe
This is the App Execution Alias / reparse point for the Store-installed PowerShell.
Additional findings:
- CodexSandboxOffline and CodexSandboxOnline exist and are enabled.
- Sandbox setup refresh completes successfully.
- codex-command-runner.exe and codex-windows-sandbox-setup.exe are present.
- Controlled Folder Access is disabled.
- I found no clear AppLocker / Code Integrity block.
- The failure happens during child-process creation, before the requested command runs.
I tested both:
[windows] sandbox = "elevated"
and:
[windows] sandbox = "unelevated"
Result in both cases: 0/8 basic read-only commands succeeded.
The agent runtime continued to launch:
C:\Users<user>\AppData\Local\Microsoft\WindowsApps\pwsh.exe
and failed with the same CreateProcessAsUserW error 5.
I also changed the Codex Desktop integrated terminal shell from PowerShell to Command Prompt. This had no effect on the agent sandbox launcher; it continued to use the WindowsApps pwsh.exe alias.
The 8-command test included:
- reading package.json
- reading src/App.tsx
- git status
- git diff
- git rev-parse
- rg searches
Because every sandboxed shell invocation fails, routine read-only work requires repeated escalation/approval. In one larger read-only audit this resulted in 41 approval requests.
This appears consistent with the packaged/MSIX PowerShell issue described here, but in Codex Desktop the agent appears to explicitly use:
%LOCALAPPDATA%\Microsoft\WindowsApps\pwsh.exe
I could not find a supported configuration option for changing the agent sandbox shell executable.
A possible fix would be for the agent shell resolver to avoid App Execution Alias / packaged PowerShell executables for sandboxed execution and fall back to a non-packaged shell such as:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Full Access only bypasses the failing sandbox and does not fix the underlying issue.
Reproduced this on Codex Desktop on Windows and can confirm the PATH-based workaround works end-to-end, with one nuance worth flagging.
Environment:
- PowerShell 7.6.4 Store/MSIX installed
- PowerShell 7.6.4 MSI also installed side-by-side at
C:\Program Files\PowerShell\7\pwsh.exe [windows] sandbox = "elevated"in config.toml
Initial datapoint (before the fix worked): with where.exe pwsh in my own interactive PowerShell session resolving the real MSIX binary (C:\Program Files\WindowsApps\Microsoft.PowerShell_7.6.4.0_x64__8wekyb3d8bbwe\pwsh.exe) ahead of the per-user alias, Codex Desktop's sandbox log still explicitly showed:
START: C:\Users\chase\AppData\Local\Microsoft\WindowsApps\pwsh.exe -Command ...
followed by CreateProcessAsUserW failed: 5 (Access is denied.). This looked like Codex was ignoring PATH order entirely and hard-resolving the per-user alias. Turned out that was an artifact of my own interactive shell (itself launched via the MSIX pwsh, which self-prepends its own directory to PATH) — not representative of the environment Codex's own process actually inherited.
What actually fixed it: removing C:\Users\chase\AppData\Local\Microsoft\WindowsApps from PATH did work — but it had to be removed from both User and Machine scope (it was present, oddly, in both — Machine PATH had a duplicate of the per-user alias folder baked in alongside the expected systemprofile WindowsApps entry), and Codex Desktop had to be fully quit (all ChatGPT.exe/codex.exe processes terminated, not just the window closed) before reopening, since PATH is only read at process start. A partial restart (window closed but background processes still alive) silently kept using the old, unfixed environment and still failed identically.
After a genuinely clean restart with both WindowsApps PATH entries removed, whoami succeeded and returned the correct principal.
Suggested addition to the fix: since this environment variable is process-inherited, any documentation or auto-detection logic should account for the fact that closing/reopening a chat window inside the Desktop app does not necessarily restart the underlying codex.exe/ChatGPT.exe process tree — a full app quit is required for a PATH change to take effect.
Separately (unrelated to this issue but hit along the way): also had to repair a corrupted deny_read_acl_state.json (0-byte/NUL-filled) and grant a narrowly-scoped WriteAttributes ACE on C:\Users\Default for the sandbox's dedicated CodexSandboxOffline/Online accounts — those were separate, unrelated pre-existing issues on this machine, now resolved, mentioned here only in case anyone else hits multiple stacked sandbox issues at once and needs to rule them out independently.
Independent reproduction from Codex Desktop on Windows, reported with user authorization.
Environment:
- Codex Desktop AppX:
OpenAI.Codex_26.803.10989.0_x64__2p2nqsd0c76g0 - Codex CLI on PATH:
0.144.1 - OS registry: ProductName
Windows 10 Pro, DisplayVersion25H2, build26200.9168, x64 [windows] sandbox = "elevated"- Microsoft Store/MSIX PowerShell
7.6.4
Observed repeatedly during ordinary read-only repository work:
windows sandbox: runner failed during SpawnChild:
CreateProcessAsUserW failed: 5 (Access is denied.)
cmd=C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\pwsh.exe -NoProfile -Command "..."
The requested Git/PowerShell command did not begin. Retrying through the approved escalated path completed the same read-only command, so this is below the repository or project harness layer.
Shell resolution evidence:
where.exe pwsh
C:\Program Files\WindowsApps\Microsoft.PowerShell_7.6.4.0_x64__8wekyb3d8bbwe\pwsh.exe
C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\pwsh.exe
Get-Command pwsh
Path: C:\Program Files\WindowsApps\Microsoft.PowerShell_7.6.4.0_x64__8wekyb3d8bbwe\pwsh.exe
C:\Program Files\PowerShell\7\pwsh.exe: absent
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe: present
The failure appears intermittent only because some simple reads can complete without reaching the failing SpawnChild path; multiple independent child-start attempts failed before execution. Setting login:false did not reliably change the outcome.
The documented diagnostic path %USERPROFILE%\.codex\.sandbox\sandbox.log is absent on this installation, and no other sandbox.log exists under %USERPROFILE%\.codex.
This matches the packaged/MSIX PowerShell boundary described in this issue. The safest user-side remedy appears to be installing machine-wide PowerShell so C:\Program Files\PowerShell\7\pwsh.exe is selected, then fully quitting and restarting Codex. Switching to unelevated is not an equivalent fix because it weakens the sandbox and has not worked consistently for Desktop reports.
Please make sandbox shell selection reject the WindowsApps/App Execution Alias target and fall back to a machine-wide PowerShell or the inbox Windows PowerShell, with an actionable error when only a packaged target is available.
Independent confirmation on current builds (user authorized public sharing; user/workspace paths omitted).
Environment
- Codex Desktop AppX:
26.820.9563.0 codex-cli 0.150.1- Windows x64, managed
workspace-writesandbox - PowerShell
7.6.5installed side-by-side:- Store/MSIX:
Microsoft.PowerShell_7.6.5.0_x64__8wekyb3d8bbwe - MSI:
C:\Program Files\PowerShell\7\pwsh.exe
- Store/MSIX:
Reproduction
The Codex process PATH resolves pwsh in this order:
C:\Program Files\WindowsApps\Microsoft.PowerShell_7.6.5.0_x64__8wekyb3d8bbwe\pwsh.exe
C:\Program Files\PowerShell\7\pwsh.exe
Direct/default PowerShell shell startup fails before command execution with:
CreateProcessAsUserW failed: 5 (Access is denied.)
The controls are deterministic in the same sandbox:
pwsh -NoLogo -NoProfile -Version
-> Access is denied (exit 1)
C:\Program Files\PowerShell\7\pwsh.exe -NoLogo -NoProfile -Version
-> PowerShell 7.6.5 (exit 0)
Additional finding: disabling the App Execution Alias is insufficient
I disabled the Store PowerShell pwsh.exe entry under Windows App execution aliases, confirmed that the per-user alias file no longer exists, fully rebooted Windows, and restarted Codex. The failure persists because Codex's process PATH still contains the Store package's direct install directory ahead of the MSI directory.
A process-local A/B test that removes only that direct Store package directory from PATH immediately succeeds:
where pwsh
-> C:\Program Files\PowerShell\7\pwsh.exe
pwsh -NoLogo -NoProfile -Version
-> PowerShell 7.6.5 (exit 0)
This matches the rust-v0.150.1 resolver behavior: which("pwsh") wins before the hard-coded MSI fallback is considered. It would help if Windows sandbox shell resolution rejected an inaccessible WindowsApps result and continued to the existing MSI fallback (C:\Program Files\PowerShell\7\pwsh.exe) before falling back to Windows PowerShell 5.1.
Root cause located in source: the fix already exists, but it is gated to the elevated backend only
Verified against rust-v0.159.2 (current latest — 0.159.2 does not change this).
Both halves are already implemented:
codex-rs/shell-command/src/shell_detect.rs:288—fallback_powershell_shell_for_elevated_windows_sandbox()rewrites the shell toPWSH_FALLBACK_PATHS = [C:\Program Files\PowerShell\7\pwsh.exe], thenPOWERSHELL_FALLBACK_PATHS(System32 5.1).targets_inaccessible_windows_apps_powershell()(shell_detect.rs:152) already flags both forms — it matches the path component after theWindowsAppssegment, so the App Execution Alias (%LOCALAPPDATA%\Microsoft\WindowsApps\pwsh.exe) trips it too, not justC:\Program Files\WindowsApps\....
What stops it firing is the caller's early return — codex-rs/core/src/tools/runtimes/mod.rs:186:
|| windows_sandbox_level != WindowsSandboxLevel::Elevated
so prepare_powershell_command_for_elevated_windows_sandbox_with_fallback returns the command unchanged for the legacy restricted-token backend. That is deliberate today and pinned by leaves_legacy_restricted_token_backend_alone (mod.rs:786), which asserts a WindowsApps\...\pwsh.exe command is passed through verbatim under WindowsSandboxLevel::RestrictedToken. That backend is selected by [windows] sandbox = "unelevated" → WindowsSandboxLevel::RestrictedToken (core/src/windows_sandbox.rs).
A/B on 0.159.2 (Windows 11 26200, only Store PowerShell 7.6.6 on PATH, [windows] sandbox = "unelevated"):
| shell resolution | -s read-only |
-s workspace-write |
|---|---|---|
| Store alias as-is | CreateProcessAsUserW failed: 5 (Access is denied.) |
same |
| unpackaged pwsh 7.6.6 ahead on PATH | runs, exit 0 | runs, exit 0 |
Installing the official MSI (PowerShell-7.6.6-win-x64.msi → C:\Program Files\PowerShell\7\pwsh.exe, added to the machine PATH, which precedes user PATH and therefore beats the alias) makes both modes pass, with Codex invoking the real executable.
Two notes for whoever picks this up:
- Winget does not fix this.
winget install Microsoft.PowerShellresolves toPowerShell-7.6.6.msixbundle, not the MSI (seeStarting StagePackageAsync ... PowerShell-7.6.6.msixbundlein the winget log) — that re-enters the MSIX path. It also failed with0x80073D02while anypwshwas running. - The ACL framing is a red herring and keeps resurfacing: the packaged
pwsh.exeACL explicitly grantsNT AUTHORITY\RESTRICTED ReadAndExecute, Synchronize(plusBUILTIN\Users ReadAndExecute), and a plain non-elevated, non-packagedProcess.Start(UseShellExecute=false) launches both the alias andC:\Program Files\WindowsApps\...\pwsh.exewith the correct exit code. Nothing is blocked at CreateProcess — it is the restricted token at spawn.
Suggested fix layer: either widen the existing gate to the restricted-token backend (identical failure class — MSIX cannot initialise under the restricted token), or reject an inaccessible-WindowsApps PowerShell during sandbox shell resolution rather than only for Elevated. Both require revisiting the pinning test above.
Another variable: the unelevated sandbox also fails while another instance of the Store pwsh is running.
Adding to the elevated/unelevated measurements above. With windows.sandbox = "unelevated", launching the Store (MSIX) pwsh fails with CreateProcessAsUserW failed: 5, or 0xC0070005 by the package's own path, whenever any other process of that package is running on the machine: an idle pwsh in a terminal, another agent's command. With no other instance it succeeds, which is why unelevated looks fine in isolated measurements and fails at random in daily use. Windows PowerShell 5.1, cmd and the MSI PowerShell 7 are unaffected.
Versions: codex-cli 0.163.0 (also 0.162.1), Windows 11 build 26200, PowerShell 7.6.6.0 from the Microsoft Store.
Minimal repro (no model needed):
- Terminal A:
pwsh -NoProfile -Command "[Console]::In.ReadLine()"(keeps a Store pwsh running). - Terminal B:
codex sandbox -- %LOCALAPPDATA%\Microsoft\WindowsApps\pwsh.exe -NoProfile -Command "exit 0"→CreateProcessAsUserW failed: 5. - Close terminal A and repeat step 2 → succeeds.
Measured 3/3 refused with the instance held open, and 3/3 Windows PowerShell 5.1 launches succeeding in the same state. This likely explains #55056 ("after an initial successful command") and the "inconsistent" reports such as #37592.
Additional Windows sandbox reproduction details (reporting with the machine owner's authorization; user, device, workspace and organization identifiers omitted).
Environment
- Windows 11 Pro, build 26300 (x64).
- Codex CLI
0.163.0, ChatGPT sign-in. - Scoped workspace:
sandbox_mode = "read-only",approval_policy = "on-request". codex doctorrun from the scoped workspace: restricted filesystem/network,backend=elevated, provisioning complete.
Failure observed in a previous read-only Agent run
windows sandbox: runner failed during SpawnChild:
CreateProcessAsUserW failed: 5 (Access is denied.)
The process did not start; the requested read-only Markdown file read did not execute.
Difference from this issue's MSIX case
The resolved command runner is a user-local pwsh.cmd wrapper under %LOCALAPPDATA%\Programs\<local-tools>\bin\, which invokes a Microsoft-signed PowerShell 7.6.7 pwsh.exe under %LOCALAPPDATA%\Programs\<local-tools>\powershell\7.6.7\. This is not a Microsoft Store/MSIX WindowsApps shell.
Read-only Get-Acl inspection showed that this wrapper, its target executable and their immediate parent directories have inherited Allow entries for SYSTEM, Administrators and the owning AzureAD principal only. No Users or CodexSandbox* entries were displayed. In contrast, the separate C:\Program Files\PowerShell\7\pwsh.exe ACL includes Users: ReadAndExecute. Both Codex sandbox local accounts exist and are enabled. Relevant Defender/CodeIntegrity event queries did not identify a matching denial.
Important limitation: the actual restricted-token SID/attributes, executable/parent-directory effective access check, and any process-creation mitigation decision were not captured. The ACL difference is a hypothesis, not a confirmed root cause. Historical setup-refresh ACL errors against C:\Windows\System32 occurred in separate runs and are not evidence of the cause of this specific child-process failure.
Maintainer guidance requested
- Is a non-MSIX user-local shell wrapper/executable with ACLs visible only to SYSTEM/Admins/owner expected to be executable by the Codex elevated Windows sandbox's restricted process token?
- Is there an officially supported read-only diagnostic to attribute the denied
CreateProcessAsUserWcall to the exact image path, token SIDs/restrictions and failing file/object/policy access check? - What supported remediation preserves the current restricted/read-only sandbox, on-request approvals and existing security enforcement?
We deliberately have not edited ACLs, PATH/shell selection, Defender, WDAC, sandbox policy, Codex hooks or any running sessions; no retry/elevated fallback was attempted. We can provide further redacted, non-sensitive diagnostics if the maintainers specify the official collection method.
Batch-wrapper compatibility addendum — 2026-10-20 (new read-only evidence)
After the initial report, a read-only inspection of the selected pwsh.cmd wrapper on the same host confirmed it is a 4-line Windows batch script (@echo off, environment-variable setup, then delegation to the locally installed signed PowerShell pwsh.exe). It is not a PE executable. An existing Codex sandbox log independently records START: %USERLOCAL_TOOLS%\\bin\\pwsh.cmd -NoProfile -Command [redacted], confirming the wrapper is the selected command head. No additional process-spawn test was run.
The Codex source at the version-matched tag rust-v0.163.0, codex-rs/windows-sandbox-rs/src/process.rs, calls CreateProcessAsUserW(h_token, NULL, cmdline, ...) (see approximately lines 170–180) and reports the resulting Win32 failure. Microsoft's CreateProcessW documentation states that running a batch file requires invoking the command interpreter (cmd.exe with /c and the batch-file path), rather than treating a batch script as the executable module. References:
- https://github.com/openai/codex/blob/rust-v0.163.0/codex-rs/windows-sandbox-rs/src/process.rs
- https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw
New hypothesis: the Windows batch-wrapper image-selection incompatibility could independently account for a pre-execution process-launch failure, alongside the previously noted user-local ACL/restricted-token issue. This is not yet proof of the specific Win32 Error 5 root cause; it does not establish the actual effective token/access check or rule out other process-launch restrictions. The matching release source is evidence of implementation but the exact installed binary was not instrumented.
Maintainer request: Could you confirm whether pwsh.cmd as the resolved PowerShell shell path is an officially supported direct CreateProcessAsUserW launch target in Windows Sandbox on Codex 0.163.0, and advise on a supported, security-preserving remediation or read-only diagnostic? We are not asking for advice to bypass the sandbox. No PATH/Shell, ACL, Defender, WDAC, Hook, sandbox or active-process changes have been made.