Skip to content

Windows: PowerShell fails with error 8009001d (NTE_PROVIDER_DLL_FAIL) in sandbox #14057

Open

Description

@eiei114

Description

On Windows 11 (10.0.26200), Codex CLI v0.111.0 always uses powershell.exe as the shell for command execution. However, PowerShell fails to start with error 8009001d (NTE_PROVIDER_DLL_FAIL - cryptographic provider DLL initialization failure) when spawned by Codex.

Environment

  • OS: Windows 11 Pro 10.0.26200
  • Codex CLI: v0.111.0
  • PowerShell: 5.1.26100.7705
  • Node: via npm global install

Steps to Reproduce

  1. Install codex-cli on Windows
  2. Run any command:
    codex exec --full-auto "echo hello"
    
  3. Observe that all PowerShell invocations fail with:
    Windows PowerShell のキャリブレーションがエラー 8009001d で失敗しました
    

Key Findings

  • powershell.exe -NoProfile -Command "echo test" works fine when called from bash/cmd directly
  • codex sandbox windows -- powershell.exe -NoProfile -Command "echo test" fails with 8009001d
  • codex sandbox windows -- cmd.exe /c "echo test" works fine
  • Error persists with ALL sandbox modes: read-only, workspace-write, danger-full-access
  • Error persists with both [windows] sandbox = "elevated" and "unelevated" config
  • Error persists with --dangerously-bypass-approvals-and-sandbox

Root Cause Analysis

The Windows restricted token created by Codex's sandbox (even in full-access mode) appears to strip privileges or SIDs required by PowerShell's cryptographic service provider initialization. Error 0x8009001d (NTE_PROVIDER_DLL_FAIL) indicates the RSA/AES crypto provider DLL cannot initialize under the restricted process token.

Since cmd.exe doesn't require cryptographic services, it works fine under the same restricted token.

Current Workaround

The model (gpt-5.3-codex) can self-correct by falling back to cmd.exe /c commands after PowerShell failure, but this wastes tokens on every session. Adding instructions to AGENTS.md to prefer cmd.exe helps.

Expected Behavior

Either:

  1. Codex should use cmd.exe as the default shell on Windows (since PowerShell requires crypto providers that the restricted token blocks)
  2. Or the restricted token should preserve the privileges needed for PowerShell crypto initialization
  3. Or provide a config option to select the shell (e.g., [windows] shell = "cmd")

Feature Flags

Relevant feature flags from codex features list:

  • elevated_windows_sandbox: removed
  • experimental_windows_sandbox: removed
  • powershell_utf8: stable (true)
  • shell_tool: stable (true)

Activity

  1. github-actions commented on Mar 9, 2026

    @github-actions
    Contributor

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

    Powered by Codex Action

  2. Sequela02 commented on Mar 28, 2026

    @Sequela02

    I've implemented a fix for this issue. The root cause is in shell.rs where
    default_user_shell() hardcodes ShellType::PowerShell on Windows. The fix
    changes Session::new in codex.rs to use ShellType::Cmd when
    windows_sandbox_level != Disabled.

    The fix includes regression tests and cargo fmt passes:
    https://github.com/Sequela02/codex/tree/fix/windows-powershell-8009001d

  3. JHD8937 commented on Apr 30, 2026

    @JHD8937

    I can reproduce this on Windows as well, and I found one additional data point that may help narrow the problem down.

    Environment:

    • Windows 10.0.19045
    • Codex CLI bundled with Codex Desktop: codex-cli 0.126.0-alpha.8
    • ~/.codex/config.toml:
    [windows]
    sandbox = "unelevated"

    The important part is that the Windows sandbox itself is not completely broken. cmd.exe works inside the sandbox:

    C:\Users\<user>\AppData\Local\OpenAI\Codex\bin\codex.exe sandbox windows C:\Windows\System32\cmd.exe /d /c echo OK

    Output:

    OK
    

    Windows PowerShell 5.1 fails inside the same sandbox:

    C:\Users\<user>\AppData\Local\OpenAI\Codex\bin\codex.exe sandbox windows C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -NonInteractive -Command "Write-Output OK"

    Result:

    exit code: 4294901760
    stderr contains: 8009001d
    

    However, PowerShell 7 works inside the same Codex Windows sandbox:

    where pwsh

    Output:

    C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\pwsh.exe
    
    C:\Users\<user>\AppData\Local\OpenAI\Codex\bin\codex.exe sandbox windows C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\pwsh.exe -NoLogo -NoProfile -NonInteractive -Command "Write-Output OK"

    Output:

    OK
    

    So on this machine the behavior is:

    cmd.exe inside Codex Windows sandbox             => works
    pwsh.exe / PowerShell 7 inside Codex sandbox     => works
    powershell.exe / Windows PowerShell 5.1 sandbox  => fails with 8009001d
    normal powershell.exe outside Codex sandbox      => works
    

    This seems to point specifically at Windows PowerShell 5.1 initialization under the Codex Windows restricted token/sandbox, rather than a general sandbox failure or a broken PowerShell installation.

    From a user-impact perspective, the built-in tool execution path still appears to use powershell.exe, so shell_command fails even though cmd.exe and pwsh.exe are viable in the same sandbox. A practical workaround would be to allow Windows users to configure the tool execution shell path, for example to pwsh.exe or cmd.exe, until the underlying Windows PowerShell 5.1 sandbox issue is fixed.

    I would prefer a proper fix in Codex if possible, but exposing a configurable Windows tool shell would also unblock this class of failures.

  4. VentureDuan commented on Apr 30, 2026

    @VentureDuan

    I seem to be having the same issue. Right now, I can't use PowerShell with either the Codex app or the Codex CLI.

  5. VentureDuan commented on Apr 30, 2026

    @VentureDuan

    Codex -> PowerShell crashes during initialization. However, it works fine on my machine with both PowerShell 5.1 and 7.

  6. added
    bug
    windows-os
    tool-calls
    on May 14, 2026
  7. yu1297937627-droid commented on Jul 26, 2026

    @yu1297937627-droid

    GitHub Issue #14057 Comment (English)

    Additional evidence: PowerShell 7 comparison + Node direct CSPRNG test

    Further diagnosis on Windows 11 + Codex Desktop 26.721.4979.0 (MSIX, Microsoft Store) confirms the failure scope is broader than initially expected.

    Environment

    • OS: Windows 11
    • Codex: OpenAI.Codex_26.721.4979.0_x64__2p2nqsd0c76g0 (Microsoft Store MSIX)
    • Config: [windows].sandbox = "unelevated", no custom [shell_environment_policy]
    • System Node: v24.18.0 (crypto works outside sandbox)
    • Newly installed PowerShell 7.6.4 MSI (C:\Program Files\PowerShell\7\pwsh.exe)

    Test 1: PowerShell 5.1 inside Codex sandbox — FAILED

    codex sandbox "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -Command 'Write-Output "ps5-ok"'
    

    Result: exit code -65536, error 8009001d (NTE_PROVIDER_DLL_FAIL).

    Test 2: PowerShell 7 inside Codex sandbox — SUCCESS

    codex sandbox "C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -NoProfile -NonInteractive -Command 'Write-Output "pwsh7-ok"'
    

    Result: output pwsh7-ok, exit code 0.

    Test 3: PowerShell 7 LanguageMode

    codex sandbox "C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -NoProfile -NonInteractive -Command '$ExecutionContext.SessionState.LanguageMode'
    

    Result: ConstrainedLanguage, exit code 0.

    Test 4: System Node directly inside Codex sandbox — CSPRNG CRASH

    Without PowerShell wrapper, directly launching system Node in the sandbox:

    codex sandbox "C:\Program Files\nodejs\node.exe" -e 'console.log(require("crypto").randomBytes(16).toString("hex"))'
    

    Result:

    Assertion failed: ncrypto::CSPRNG(nullptr, 0)
    Exit: 134
    

    Test 5: Codex UI Full Access mode — STILL FAILS

    Switched to Full Access in Codex UI, ran cmd / PowerShell / Node minimal tests — all 8009001d / -65536.

    ProcMon evidence summary

    ProcMon captured PowerShell 5.1 launching inside the sandbox:

    • Read Crypto provider config (rsaenh.dll) → SUCCESS
    • Load rsaenh.dll → SUCCESS
    • RegCreateKey write HKCU\Software\Policies\Microsoft\SystemCertificates\CA → ACCESS DENIED (Read/Write, Delete)
    • RegCreateKey write HKLM\SOFTWARE\Microsoft\SystemCertificates\CA → ACCESS DENIED
    • RegCreateKey write HKLM\SOFTWARE\Microsoft\SystemCertificates\ROOT → ACCESS DENIED
    • All SystemCertificates registry writes denied → 8009001d

    Full .PML (583 MB) and CSV (264 MB) retained. Available via private read-only link if a maintainer requests it. Not uploading publicly to avoid leaking username/path/environment variables.

    Conclusions

    1. PowerShell 5.1 fails in Codex's write-restricted token because SystemCertificates registry writes are denied → 8009001d.
    2. PowerShell 7 launches but is constrained by ConstrainedLanguage mode.
    3. System Node directly in the sandbox also crashes CSPRNG (ncrypto::CSPRNG(nullptr, 0), exit 134) — proving the issue is not limited to PowerShell 5.1; Codex's restricted context also has a Node/CNG compatibility problem.
    4. Codex desktop agent tooling still hardcodes PowerShell 5.1, even when PowerShell 7 is installed.
    5. UI Full Access mode does not bypass the failure path.

    Requests

    1. Prioritize support for auto-selecting pwsh.exe or configurable agent shell (ref Windows: allow configuring the default session shell via config #16579).
    2. Investigate write-restricted token denying SystemCertificates writes causing PowerShell 5.1 Crypto initialization failure.
    3. Investigate Node.js ncrypto::CSPRNG assertion failure under restricted context.
    4. Evaluate whether Full Access mode truly bypasses the restricted token path.

    Reproduction steps

    1. Windows 11, install Codex Desktop (Microsoft Store MSIX)
    2. config.toml: [windows].sandbox = "unelevated"
    3. codex sandbox "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -Command 'echo ok' → exit -65536
    4. codex sandbox "C:\Program Files\nodejs\node.exe" -e "console.log(require('crypto').randomBytes(16).toString('hex'))" → exit 134 (CSPRNG)
    5. codex sandbox "C:\Program Files\PowerShell\7\pwsh.exe" -NoProfile -Command 'echo ok' → exit 0 ✅

    Related issues

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

    bugtool-callswindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions