Aident AI

Codex CreateProcessAsUserW Failed: 5? Check the PowerShell Path
If Codex on Windows reports CreateProcessAsUserW failed: 5 (Access is denied.), inspect the command path in ~\.codex\.sandbox\sandbox.log before changing permissions. When that path points into C:\Program Files\WindowsApps\Microsoft.PowerShell_...\pwsh.exe, install a non-packaged PowerShell build, put C:\Program Files\PowerShell\7 ahead of the Store build for Codex, restart the app, and repeat one read-only command. Do not run Codex as administrator, take ownership of WindowsApps, or disable the sandbox to hide the error.
This is a narrow fix for the packaged-PowerShell branch. Error 5 can also come from workspace ACLs, missing sandbox accounts, enterprise policy, ARM64 behavior, or another executable. The log path is the deciding evidence.
Prerequisites
Before changing anything:
Save open work and stop the failed Codex task.
Open a normal PowerShell window outside Codex.
Record the Codex version and Windows build.
Keep the current sandbox log. It distinguishes this branch from look-alike access failures.
Use one disposable or clean repository for the verification task.
The commands below only read command resolution and recent log lines:
Expected result for this branch: pwsh.exe resolves to a path under C:\Program Files\WindowsApps\Microsoft.PowerShell_..., and a nearby log line ends with CreateProcessAsUserW failed: 5.
If the log names powershell.exe, cmd.exe, git.exe, an ARM64 binary, or a workspace file instead, stop here. Use the broader Codex Windows sandbox error guide and diagnose that boundary instead of forcing this fix.
Why the Store Path Matters
OpenAI Codex issue 35871 isolates the shell path on one Windows machine. The reporter ran 20 trials for each shell: the Microsoft Store or MSIX PowerShell path failed 20 of 20 times, while Windows PowerShell 5.1, cmd.exe, and Git Bash failed 0 of 20 times. The same codex exec test worked after the WindowsApps entries were removed from the PATH passed to Codex.
That is strong reproduction evidence, not a promise that every error 5 has the same cause. Earlier reports such as issue 10090 show the same WindowsApps PowerShell path in sandbox.log, while other reports identify different ACL and platform branches.
Windows uses CreateProcessAsUserW to create a process in another user's security context. Codex's Windows sandbox uses a restricted context. The observed failure occurs before PowerShell runs, so changing the PowerShell command or project file usually cannot fix this particular branch.
Step 1: Confirm the Packaged Shell, Not Just Error 5
Capture the resolved executables with their versions:
Then match the latest runner and failure lines:
You have a match only when the failed runner start command names a PowerShell executable below C:\Program Files\WindowsApps.
Do not assume that the first item returned by Get-Command is what an already-running desktop app uses. The sandbox log records what Codex actually attempted.
Step 2: Install a Non-Packaged PowerShell Build
Use Microsoft's PowerShell installation guide. The supported options include the official MSI package and WinGet. For WinGet:
If PowerShell is already installed through that package, WinGet may offer an upgrade instead. Close the terminal after installation and open a new one so it receives the updated PATH.
Verify the non-packaged executable directly:
Expected result: Test-Path returns True, and the second command prints a PowerShell 7 version. Microsoft documents $Env:ProgramFiles\PowerShell\7 as the default MSI installation directory.
Step 3: Verify PATH Order Without Deleting WindowsApps
Open a new normal PowerShell window:
Expected result: the first path is C:\Program Files\PowerShell\7\pwsh.exe, not a path under C:\Program Files\WindowsApps.
If the Store build still comes first, inspect the user PATH without changing it:
Use System Properties > Environment Variables to move C:\Program Files\PowerShell\7 before the relevant WindowsApps entry. Do not delete WindowsApps from the machine-wide PATH; other app execution aliases can depend on it.
For a temporary current-terminal check, prepend only the MSI directory:
This proves command resolution in that terminal only. Codex Desktop must be fully restarted after the persistent PATH order is corrected.
Step 4: Restart Codex and Run One Read-Only Test
Fully quit Codex, including its system-tray process, then reopen it. In a clean repository, ask:
After the task completes, recheck the log:
Success means all three conditions hold:
the latest runner uses
C:\Program Files\PowerShell\7\pwsh.exeor another non-packaged shell;the read-only command returns its expected directory; and
no new
CreateProcessAsUserW failed: 5line appears for that run.
Do not use a file edit as the first test. A read-only command isolates process creation from separate workspace write-permission failures.
If the Error Persists
Use the evidence to choose the next branch:
Latest evidence | What it means | Next check |
|---|---|---|
Runner still names | Codex did not receive the corrected PATH | Fully exit the app, verify PATH in a new terminal, then restart Windows if required |
Runner names | The packaged-shell diagnosis did not resolve the failure | Preserve the log and inspect sandbox accounts, policy, and workspace ACLs |
Read-only commands work but edits fail | Process creation is fixed; write permissions are separate | Test one clean local repository and inspect the failing path's ACL |
Error appears only for one executable | That executable, not PowerShell resolution, is the boundary | Record its exact path, architecture, and signature |
ARM64 machine or enterprise policy appears in the report | A platform-specific branch may apply | Add the sanitized environment to the closest upstream issue |
The existing Codex Windows sandbox guide covers these broader branches. If you need stronger isolation for agent work while the desktop issue is unresolved, compare a Docker sandbox workflow in a disposable repository.
Common Failure Modes
Mistake | Why it is risky or misleading | Safer response |
|---|---|---|
Running Codex as administrator | It changes the security boundary and can hide the real failure | Keep Codex non-admin and fix the resolved shell path |
Taking ownership of | It can damage Store package permissions and updates | Install the supported non-packaged PowerShell build |
Deleting every WindowsApps PATH entry | Other app aliases may rely on that directory | Put the MSI PowerShell directory first |
Switching the sandbox to unelevated as a permanent fix | It changes isolation and does not repair shell resolution | Use the normal sandbox after correcting the path |
Editing project ACLs before reading the runner path | Workspace permissions cannot fix a packaged shell that never starts | Classify the executable path first |
Testing many commands at once | Mixed read, write, and spawn failures blur the result | Run one read-only command, then expand |
Why This Sequence Works
The sequence changes one boundary at a time. The sandbox log identifies the exact executable Codex tried to spawn. The official PowerShell installer supplies a normal executable outside the Store package directory. PATH verification ensures Codex selects that executable, and the one-command control proves process creation before write permissions enter the test.
This applies the useful structure behind Aident's Ollama networking guide: match exact terminology, answer early, use reproducible checks, state the expected result, and separate adjacent failures instead of guessing from one symptom.
Verify the Evidence Through Aident Loadout
Follow https://aident.ai/SETUP.md
With Codex Desktop closed, use the installed public aident CLI to confirm authentication and discover a current read-only GitHub issue-search Action:
Ask Aident Loadout to inspect the returned Action schema, preflight a bounded query for repo:openai/codex is:issue "CreateProcessAsUserW failed: 5", and execute it only after the preflight is accepted. Success is one current result set, no provider credential copied into the prompt, and no repository change.
Use Aident Loadout to verify that one hosted read-only Action while the local desktop sandbox remains closed.
Sources
Windows sandbox failure when the resolved shell is the Store build of PowerShell, OpenAI Codex issue, opened July 29, 2026
Elevated Windows sandbox commands fail with no output, OpenAI Codex issue, opened January 28, 2026
Codex resolves an unusable PowerShell alias on Windows, OpenAI Codex issue, opened April 22, 2026
Install PowerShell on Windows, Microsoft Learn, accessed August 3, 2026
CreateProcessAsUserWfunction, Microsoft Learn, accessed August 3, 2026
Refresh this guide when Codex changes Windows shell resolution, sandbox user creation, PATH handling, the default sandbox mode, or the Store and MSI PowerShell compatibility behavior.


