Repository navigation
Description
Summary
On Windows, Codex can end up unable to execute any PowerShell-backed shell commands even when the user has a valid PowerShell installation and the Codex config is already set to the most permissive options.
In my case, even trivial shell-tool commands like printing the working directory failed until the PowerShell resolution path was corrected.
This showed up as:
- shell/PowerShell commands consistently failing in the Codex environment
- the model falling back to doing as much as it could in the JS REPL instead
- for anything it could not do in JS REPL, the model would often explain that PowerShell commands were blocked in its environment
This was especially confusing because I had already tried making the environment fully permissive:
- full filesystem access / danger-full-access
- permissive approval settings
- permissive
config.tomlsettings
So from the user side, this looked like a Codex runtime/sandbox failure rather than a local shell-path issue.
Likely root cause
On this machine, PATH surfaced a WindowsApps pwsh.exe alias before the real PowerShell 7 executable.
Codex currently resolves PowerShell through the generic shell lookup path in codex-rs/core/src/shell.rs, which uses PATH/which("pwsh") before the explicit fallback path. That means it can select an alias that looks valid enough to resolve but is not actually usable for Codex process execution.
The end result was that Codex effectively could not execute PowerShell commands at all.
Why this matters
When this happens, the user-visible failure mode is pretty bad:
- shell commands fail broadly
- the model starts routing more work through JS REPL
- tasks that require real shell execution stay blocked
- the assistant can end up repeatedly telling the user that PowerShell is unavailable in the environment
That is a rough degradation path for Windows users because it can make the tool feel fundamentally broken even though the machine has a working PowerShell install.
Proposed fix
Use the existing PowerShell-specific validated discovery helpers for Windows PowerShell selection before falling back to the generic PATH-first shell lookup.
Concretely:
- preserve explicit caller-provided shell paths
- prefer validated
pwshdiscovery - then prefer validated
powershell.exediscovery - only after those fail, fall back to the old generic shell lookup path
This keeps the change narrowly scoped to Windows PowerShell selection and reuses logic the repo already has for probing whether a PowerShell executable is actually runnable.
Local patch / validation
I prepared and tested a local patch that makes this change in:
codex-rs/core/src/shell.rs
Locally validated on Windows with:
cargo test -p codex-core powershell_shell_prefers_validated_executable_discovery -- --nocapturecargo test -p codex-core test_detect_shell_type -- --nocapture
Both passed.
Patch availability
I have a working branch with the fix here:
- branch:
jarmen423/windows-powershell-shell-resolution - commit:
a91630011
Compare link:
I noticed that this repo currently restricts PR creation to collaborators, so I could not open a PR directly from my fork. If this fix looks useful, feel free to cherry-pick or recreate it from that branch/commit.
Activity
github-actions commentedon Apr 22, 2026
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
slix commentedon Aug 2, 2026
Still reproducible with Codex Desktop 26.727.6591.0 on Windows 10 22H2 build 19045 and PowerShell 7.6.4 MSIX.
Codex selected
%LOCALAPPDATA%\Microsoft\WindowsApps\pwsh.exe. Commands failed in both unelevated and elevated Windows sandboxes with:Installing the MSI side-by-side was insufficient while the MSIX alias remained. After removing the MSIX package, Codex selected
C:\Program Files\PowerShell\7\pwsh.exeand both sandboxes worked, including bundled Node/Python and workspace access.Feedback ID:
019f22c0-430b-7163-b40d-1e72397e2ffcerfeeneo-rgb commentedon Aug 12, 2026
I reproduced the same underlying WindowsApps
pwsh.exeresolution problem, with a slightly different sandbox failure code, and confirmed the workaround/fix with an A/B test.Environment / symptom
10.0.26300.0, x64)pwshto:Normal Codex work frequently showed transient shell/PowerShell failures and then recovered through retry/fallback.
A minimal sandbox-only test failed before the requested executable could spawn with:
The raw runner command showed the outer shell was always the WindowsApps alias, even when the requested command was
cmd.exeor Windows PowerShell 5.1, e.g. conceptually:So the requested child executable never got a chance to run; the failure occurred while spawning the outer
pwsh.exealias.A/B validation
App Execution Aliasin Windows Settings.where.exe pwshthen returned no result.This removed the recurring sandbox/PowerShell error messages in normal Codex use.
Final fix
I then removed the Store/MSIX PowerShell package and installed PowerShell 7.6.4 via the MSI/WiX installer so that the real executable lives at:
After restarting Codex, a direct Windows-sandbox test (no fallback/escalation) reported:
I also tested normal operations afterward in Codex Desktop and in the Codex browser sidebar; the previously recurring shell-error messages no longer appeared.
So in this case the root cause was not PowerShell 7 itself, ExecutionPolicy, PATH in general, workspace permissions, or the sandbox being fundamentally broken. It was specifically Codex selecting the Store/MSIX
pwsh.exeApp Execution Alias fromMicrosoft\WindowsApps, which could not be spawned correctly by the Windows sandbox runner. Replacing it with the real MSI/WiXpwsh.exeresolved the issue.This is very similar to the existing report above, but the observed Windows error was
1312rather than5, so I wanted to add the variant and the A/B confirmation here.elliejayliquid commentedon Sep 7, 2026
Constant issues with PowerShell commands, too, on the latest Codex Desktop update. Keeps failing, then trying to find a workaround, burning tokens like crazy. The project is a trusted project.
matthewbaines-ops commentedon Sep 26, 2026
Title: Windows CLI 0.149.0: explicit System32 PowerShell shell request instead attempts WindowsApps pwsh.exe and fails with error 5
Summary
In a controlled Windows diagnostic, the model explicitly supplied System32 Windows PowerShell as the
shellargument totools.exec_command. The resulting error instead reported an attempted launch of the per-user WindowsAppspwsh.exealias.That attempted launch failed with
CreateProcessAsUserW failed: 5 (Access is denied.).Could you confirm whether this shell substitution is intended, and which component determines the executable used by unified exec?
Environment
0.149.0, launched through the pinnedcodex.cmdfrom Git Bash.CODEX_HOME; memories disabled.workspace-write, network access enabled.--json,--strict-config,--skip-git-repo-check.never.CodexSandboxService.OpenAI.Codexremained running.Diagnostic procedure
The model was instructed to:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.Write-Output MDP-SBX-OK.pwsh.exepath.Only the first command-tool call was made.
Captured tool request
The retained rollout excerpt records
tools.exec_commandreceiving these exact fields:{ "cmd": "Write-Output MDP-SBX-OK", "shell": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "yield_time_ms": 10000 }This excerpt omits a numeric output-limit argument. The
shellandcmdfields are unchanged.Observed result
The error reported this executable instead:
The reported launcher command included:
The rejection included:
Additional captured values:
No
MDP-SBX-OKoutput was produced. The conditional second call was not made.The overall
codex execprocess exited 0 after the model reported the rejection; this did not mean the command succeeded.Expected behaviour
Either use the explicitly supplied System32 PowerShell executable, or clearly report that the
shellargument cannot be honoured.An attempt using a different executable cannot establish whether the requested System32 executable works in this sandbox.
What this establishes—and what it does not
The captured tool argument and reported attempted executable differ.
This does not establish:
The diagnostic outcome was classified as inconclusive. No fallback, unsandboxed run, permissions change or subsequent diagnostic was performed.
Evidence availability
A redacted summary containing the tool request, rejection and effective policy is retained locally.
Its SHA-256 is:
Raw captures remain private because they contain personal paths. The full session rollout was not retained after the approved disposable-environment cleanup; its permitted excerpts and hash were preserved in the summary.
I can provide the redacted summary if useful.
Yang-kai-cmd commentedon Oct 20, 2026
Additional evidence: Codex 0.163.0 through T3 Code on Windows, PowerShell 7.6.7, with
tty:true. This report keeps executable selection separate from the unresolved process-creation failure; it does not claim a confirmed bug.Observed behavior and version evidence
A previously verified PowerShell executable was supplied via
exec_command.shell, but the launcher reported the WindowsApps alias instead. The session used full filesystem access with approval policynever; the captured error namesCreateProcessW, rather than theCreateProcessAsUserWerror reported above.The installed Codex package version was previously observed as 0.163.0. The source trace below is from the public
rust-v0.163.0release tag. The installed executable has not been verified against that source.Sanitized request and error
Paths are sanitized;
cmdis summarized, not reproduced as an executable command:{ "shell": "C:\\Program Files\\WindowsApps\\Microsoft.PowerShell_7.6.7.0_x64__8wekyb3d8bbwe\\pwsh.exe", "workdir": "E:\\<project>", "login": false, "tty": true, "yield_time_ms": 10000, "max_output_tokens": 1000 }The command checked the PowerShell version and console redirection, then waited up to 30 seconds for fixed, non-sensitive input. Its exact source passed PowerShell parsing with zero errors before submission.
The reported executable was:
The returned failure included:
The launcher truncated the command body in its error response; a complete, untruncated error is unavailable. No diagnostic command output or running session was returned. No further reproduction was performed to obtain a longer error.
Source trace: executable selection
get_command()passes the supplied path toget_shell_by_model_provided_path().pwshthroughPATHbefore fallback locations.CreateProcessW, and formats the observed failure.This source behavior explains how an explicit path can lead back to an alias. It does not establish the reason Windows denied process creation, nor that changing the
shellargument again would resolve it.Contract clarification / maintainer questions
shellintended to select a shell type or pin an executable path? The exposed description says “Shell binary to launch.”CreateProcessW/ WindowsAppsAccess is deniedresult be investigated separately?No credential data is included. No configuration, permissions, or policy changes were made as a workaround.
kalex01 commentedon Nov 1, 2026
Additional Windows Codex Desktop approval-stage observation (recorded 2026-10-24; not reproduced or rerun). This may be related to shell rediscovery but is not evidence that our wrapper was a WindowsApps alias.
A narrowly scoped
exec_commandrequest specified:shell: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exelogin: false;sandbox_permissions: require_escalatedcmdexplicitly called& 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -NoLogo -NoProfile -NonInteractive -File '<workspace>\diagnostic.ps1'Before any diagnostic process started, automatic approval review rejected the request with this recorded explanation:
We received no native exit code, process-tree evidence or diagnostic output. We did not retry, change shell/tools, weaken permissions, or run a probe to work around the rejection. The app version later reported by desktop metadata was
26.1027.30824, but neither that value nor its relation to the historicalexec_commandbackend has been independently attested.Questions for maintainers:
exec_command.shellpath intended to pin the actual entry executable, or only to select a shell type before internal rediscovery?pwsh.exebefore that requested shell? What authoritative, non-executing source can identify the exact wrapper path/build and the effective process/argv chain?The problem here is approval-chain identity and evidence, not a demonstrated PowerShell crash. Please don't assume the wrapper identity or recommend an unreviewed indirect launch. Sanitized report only; no project path, credentials, financial data or raw logs included.
kalex01 commentedon Nov 1, 2026
Following up on our earlier approval-stage inquiry: could a maintainer identify the responsible Codex execution/approval-service owner or the supported route for a non-executing contract review?
We need authoritative versioned documentation or existing service records that clarify:
exec_command.shellpins an executable or selects a type for rediscovery, and whether a supported direct executable-plus-argv contract exists.Please distinguish behavior applicable to the historical request from current service behavior and generic CLI behavior; mark unsupported facts explicitly. If host-specific records cannot be provided in this public issue, identifying the responsible owner and an approved nonsecret review route would help.
This is a request for existing evidence, not a runtime reproduction. Please do not request command execution, permission changes, credentials, private project paths, raw logs, environment values or customer data. We have not rerun the diagnostic or changed execution tools to work around the rejection.