codex - 💡(How to fix) Fix Windows: `shell_command` fails during PowerShell initialization with `Win32Exception (126)`, while manual `pwsh` / `powershell.exe` commands work [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#17326Fetched 2026-04-11 06:17:40
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
labeled ×4commented ×1unlabeled ×1

On Windows, Codex Desktop can attach to the thread terminal successfully, but every shell_command call fails before the command actually runs.

This happens both inside the sandbox and outside the sandbox.

The failure occurs during PowerShell initialization, even for a minimal command like:

cmd /c echo TERMINAL_OK

Error Message

The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception. at System.Environment.FailFast(System.Threading.StackCrawlMark ByRef, System.String, System.Exception, System.String) at System.Environment.FailFast(System.String, System.Exception) System.TypeInitializationException: The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception. --- End of inner exception stack trace ---

Root Cause

On Windows, Codex Desktop can attach to the thread terminal successfully, but every shell_command call fails before the command actually runs.

This happens both inside the sandbox and outside the sandbox.

The failure occurs during PowerShell initialization, even for a minimal command like:

cmd /c echo TERMINAL_OK
RAW_BUFFERClick to expand / collapse

What version of the Codex App are you using (From “About Codex” dialog)?

Codex version: [fill in]

What subscription do you have?

plus

What platform is your computer?

OS: Windows 11

What issue are you seeing?

Title: Windows: shell_command fails during PowerShell initialization with Win32Exception (126), while manual pwsh / powershell.exe commands work

Body:

Summary

On Windows, Codex Desktop can attach to the thread terminal successfully, but every shell_command call fails before the command actually runs.

This happens both inside the sandbox and outside the sandbox.

The failure occurs during PowerShell initialization, even for a minimal command like:

cmd /c echo TERMINAL_OK


### What steps can reproduce the bug?

Process terminated.
The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception.
   at System.Environment.FailFast(System.Runtime.CompilerServices.StackCrawlMarkHandle, System.String, System.Runtime.CompilerServices.ObjectHandleOnStack, System.String)
   at System.Environment.FailFast(System.Threading.StackCrawlMark ByRef, System.String, System.Exception, System.String)
   at System.Environment.FailFast(System.String, System.Exception)
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String[], Int32)
   at Microsoft.PowerShell.ManagedPSEntry.Main(System.String[])
System.TypeInitializationException: The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception.
 ---> System.ComponentModel.Win32Exception (126): 找不到指定的模块。
   at System.Management.Automation.Internal.SecuritySupport.GetSaferPolicy(String path, SafeHandle handle)
   at System.Management.Automation.Security.SystemPolicy.TestSaferPolicy(String testPathScript, String testPathModule)
   at System.Management.Automation.Security.SystemPolicy.GetAppLockerPolicy(String path, SafeHandle handle)
   at System.Management.Automation.Security.SystemPolicy.GetLockdownPolicy(String path, SafeHandle handle, Nullable`1 canExecuteResult)
   at System.Management.Automation.Security.SystemPolicy.GetLockdownPolicy(String path, SafeHandle handle)
   at System.Management.Automation.Security.SystemPolicy.GetSystemLockdownPolicy()
   at System.Management.Automation.Runspaces.InitialSessionState..cctor()
   --- End of inner exception stack trace ---
   at System.Management.Automation.Runspaces.InitialSessionState.CreateDefault2()
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(String[] args, Int32 argc)


### What is the expected behavior?

_No response_

### Additional information

_No response_

extent analysis

TL;DR

The shell_command failure in Codex App on Windows 11 may be resolved by investigating and configuring the system's AppLocker policy or PowerShell execution policies.

Guidance

  • Verify the system's AppLocker policy to ensure it is not blocking PowerShell execution, as indicated by the Win32Exception (126) error.
  • Check the PowerShell execution policies using the Get-ExecutionPolicy cmdlet to ensure they are set to allow script execution.
  • Investigate the system's configuration for any restrictions on running PowerShell, such as Group Policy settings.
  • Consider running the Codex App with elevated privileges or as an administrator to see if it resolves the issue.

Example

No code snippet is provided as the issue seems to be related to system configuration rather than code.

Notes

The error message System.ComponentModel.Win32Exception (126): 找不到指定的模块。 translates to "The specified module was not found." This suggests a potential issue with the system's configuration or environment variables.

Recommendation

Apply workaround: Investigate and configure the system's AppLocker policy and PowerShell execution policies to allow the Codex App to run shell_command successfully. This is recommended as the issue seems to be related to system configuration rather than a bug in the Codex App itself.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING