Skip to content

Windows: Codex can fail to execute any PowerShell shell commands when PATH resolves an unusable pwsh alias #18937

Open

Description

@jarmen423

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.toml settings

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 pwsh discovery
  • then prefer validated powershell.exe discovery
  • 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 -- --nocapture
  • cargo 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

  1. added
    bug
    CLI
    windows-os
    tool-calls
    on Apr 22, 2026
  2. slix commented on Aug 2, 2026

    @slix

    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:

    CreateProcessAsUserW failed: 5 (Access is denied.)
    

    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.exe and both sandboxes worked, including bundled Node/Python and workspace access.

    Feedback ID: 019f22c0-430b-7163-b40d-1e72397e2ffc

  3. erfeeneo-rgb commented on Aug 12, 2026

    @erfeeneo-rgb

    I reproduced the same underlying WindowsApps pwsh.exe resolution problem, with a slightly different sandbox failure code, and confirmed the workaround/fix with an A/B test.

    Environment / symptom

    • Windows 11 (build reported by Codex diagnostics: 10.0.26300.0, x64)
    • PowerShell 7.6.4 originally installed as Store/MSIX
    • Codex was resolving pwsh to:
    %LOCALAPPDATA%\Microsoft\WindowsApps\pwsh.exe
    

    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:

    windows sandbox: runner failed during SpawnChild: CreateProcessAsUserW failed: 1312
    (A specified logon session does not exist. It may already have been terminated.)
    

    The raw runner command showed the outer shell was always the WindowsApps alias, even when the requested command was cmd.exe or Windows PowerShell 5.1, e.g. conceptually:

    %LOCALAPPDATA%\Microsoft\WindowsApps\pwsh.exe -NoProfile -Command "... & 'C:\Windows\System32\cmd.exe' ..."
    

    So the requested child executable never got a chance to run; the failure occurred while spawning the outer pwsh.exe alias.

    A/B validation

    1. I disabled the PowerShell App Execution Alias in Windows Settings.
    2. where.exe pwsh then returned no result.
    3. I fully restarted Codex and opened a fresh thread.
    4. The same sandbox-only diagnostic succeeded, with Codex falling back to Windows PowerShell 5.1:
    PowerShell version: 5.1.26100.8935
    Executable: C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
    Exit code: 0
    Raw runner error: none
    

    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:

    C:\Program Files\PowerShell\7\pwsh.exe
    

    After restarting Codex, a direct Windows-sandbox test (no fallback/escalation) reported:

    PowerShell version: 7.6.4
    Executable: C:\Program Files\PowerShell\7\pwsh.exe
    Exit code: 0
    Raw runner error: none
    

    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.exe App Execution Alias from Microsoft\WindowsApps, which could not be spawned correctly by the Windows sandbox runner. Replacing it with the real MSI/WiX pwsh.exe resolved the issue.

    This is very similar to the existing report above, but the observed Windows error was 1312 rather than 5, so I wanted to add the variant and the A/B confirmation here.

  4. elliejayliquid commented on Sep 7, 2026

    @elliejayliquid

    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.

  5. matthewbaines-ops commented on Sep 26, 2026

    @matthewbaines-ops

    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 shell argument to tools.exec_command. The resulting error instead reported an attempted launch of the per-user WindowsApps pwsh.exe alias.

    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

    • Codex CLI: 0.149.0, launched through the pinned codex.cmd from Git Bash.
    • Native Windows elevated sandbox.
    • Fresh disposable CODEX_HOME; memories disabled.
    • Empty disposable working directory outside Windows Temp.
    • workspace-write, network access enabled.
    • --json, --strict-config, --skip-git-repo-check.
    • Effective approval policy recorded as never.
    • Codex Desktop was closed.
    • CodexSandboxService.OpenAI.Codex remained running.
    • Run date: 2026-09-26.
    • Exact Windows build was not captured in the retained summary.

    Diagnostic procedure

    The model was instructed to:

    1. Explicitly select C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.
    2. Run only Write-Output MDP-SBX-OK.
    3. Only if that succeeded with the exact marker, try the WindowsApps pwsh.exe path.
    4. Stop immediately on rejection or unexpected output, without retries, fallback shells or requests for additional permissions.

    Only the first command-tool call was made.

    Captured tool request

    The retained rollout excerpt records tools.exec_command receiving 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 shell and cmd fields are unchanged.

    Observed result

    The error reported this executable instead:

    <OPERATOR-HOME>\AppData\Local\Microsoft\WindowsApps\pwsh.exe
    

    The reported launcher command included:

    pwsh.exe -NoProfile -Command "try { [Console]::OutputEncoding=[System.Text.Encoding]::UTF8 } catch {}
    Write-Output MDP-SBX-OK"
    

    The rejection included:

    Failed to create unified exec process:
    runner failed during SpawnChild:
    CreateProcessAsUserW failed: 5 (Access is denied.)
    

    Additional captured values:

    si_flags=256
    creation_flags=525312
    Windows error 5
    

    No MDP-SBX-OK output was produced. The conditional second call was not made.

    The overall codex exec process 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 shell argument 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:

    • Why the executable selection differed.
    • Whether System32 PowerShell would have succeeded.
    • Whether the WindowsApps alias itself is the cause of the access denial.
    • Whether the same behaviour occurs on another Codex version or Windows installation.

    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:

    36a205145f02cdab94efb329f1a9b994ed2772cbf816245af44d555df96e36ad
    

    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.

  6. Yang-kai-cmd commented on Oct 20, 2026

    @Yang-kai-cmd

    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 policy never; the captured error names CreateProcessW, rather than the CreateProcessAsUserW error 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.0 release tag. The installed executable has not been verified against that source.

    Sanitized request and error

    Paths are sanitized; cmd is 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:

    C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\Microsoft.PowerShell_8wekyb3d8bbwe\pwsh.exe
    

    The returned failure included:

    Failed to create unified exec process: CreateProcessW …
    failed: Access is denied. (os error 5)
    

    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 to get_shell_by_model_provided_path().
    • Shell discovery uses that path to identify the shell type, then discovers the executable again. PowerShell discovery searches for pwsh through PATH before fallback locations.
    • The Windows interactive launcher builds the command line, calls 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 shell argument again would resolve it.

    Contract clarification / maintainer questions

    1. Is shell intended to select a shell type or pin an executable path? The exposed description says “Shell binary to launch.”
    2. Is executable rediscovery intentional when an absolute path is supplied?
    3. Is there a supported way to select a specific PowerShell executable for interactive execution?
    4. Should this CreateProcessW / WindowsApps Access is denied result be investigated separately?

    No credential data is included. No configuration, permissions, or policy changes were made as a workaround.

  7. kalex01 commented on Nov 1, 2026

    @kalex01

    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_command request specified:

    • shell: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    • login: false; sandbox_permissions: require_escalated
    • cmd explicitly called & 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -NoLogo -NoProfile -NonInteractive -File '<workspace>\diagnostic.ps1'
    • Fixed workspace as working directory.

    Before any diagnostic process started, automatic approval review rejected the request with this recorded explanation:

    The user approved the exact pinned Windows PowerShell invocation, but this action adds an unapproved cached pwsh.exe wrapper, so it is not the authorized command.

    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 historical exec_command backend has been independently attested.

    Questions for maintainers:

    1. Is an absolute exec_command.shell path intended to pin the actual entry executable, or only to select a shell type before internal rediscovery?
    2. Does unified exec intentionally add a cached pwsh.exe before that requested shell? What authoritative, non-executing source can identify the exact wrapper path/build and the effective process/argv chain?
    3. Is there a supported host-specific direct executable-plus-argv launch contract with no additional wrapper, or a way to attest the full expanded chain (startup, privileges, output/exit and cleanup) before requesting narrowly scoped permission?

    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.

  8. kalex01 commented on Nov 1, 2026

    @kalex01

    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:

    1. Whether an absolute exec_command.shell pins an executable or selects a type for rediscovery, and whether a supported direct executable-plus-argv contract exists.
    2. Any introduced intermediary, its executable identity/hash provenance, parent-child topology and argument forwarding.
    3. Startup/profile/login and working-directory rules, inherited environment names/rules only, per-layer privilege/sandbox boundaries, stdout/stderr and exit propagation, outer deadlines/cancellation, process ownership and cleanup guarantees.

    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.

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

    CLIbugtool-callswindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions