Codex App: In a Windows environment, Codex cannot initialize PowerShell

Open 💬 9 comments Opened Apr 29, 2026 by VentureDuan
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

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

codex app 26.426.12240

What subscription do you have?

plus

What platform is your computer?

x64

View original on GitHub ↗

9 Comments

VentureDuan · 2 months ago

Windows: shell_command fails during PowerShell initialization with InitialSessionState / GetSaferPolicy / Win32Exception (126), while manual PowerShell works

Summary

On Windows, Codex Desktop shell_command fails before the actual command runs.

The failure happens during PowerShell initialization, with this stack shape:

  • System.Management.Automation.Runspaces.InitialSessionState
  • System.Management.Automation.Internal.SecuritySupport.GetSaferPolicy
  • System.Management.Automation.Security.SystemPolicy.GetAppLockerPolicy
  • System.ComponentModel.Win32Exception (126): The specified module could not be found

Important context:

  • Manual powershell.exe works
  • Manual pwsh.exe works
  • Replaying the same env_map and cwd captured from Codex sandbox requests in a normal child process also works
  • The failure appears specific to the Codex Windows shell_command runner / sandbox host environment

This looks very similar to:

  • #14221
  • #17326

What version of the Codex App are you using?

Observed local package versions/log references include:

  • OpenAI.Codex_26.415.4716.0_x64__2p2nqsd0c76g0
  • OpenAI.Codex_26.422.3464.0_x64__2p2nqsd0c76g0

The failing local runner path observed in logs is:

  • C:\Users\Administrator\.codex\.sandbox-bin\codex-command-runner-0.125.0-alpha.3.exe

Platform

  • OS: Windows 11
  • Shell environment: Windows native
  • Date observed: April 29, 2026

Repro

Inside Codex Desktop, ask the agent to run even a trivial shell command, for example:

$PSVersionTable.PSVersion.ToString()

or:

cmd /c echo TERMINAL_OK

Actual behavior

shell_command fails before the command executes.

Observed error:

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)

Expected behavior

shell_command should run the command successfully, the same way it works in a normal Windows terminal.

Important findings from local investigation

1. Manual PowerShell works

These succeed outside Codex shell_command:

powershell.exe -NoLogo -NoProfile -Command $PSVersionTable.PSVersion.ToString()
pwsh.exe -NoLogo -NoProfile -Command $PSVersionTable.PSVersion.ToString()

pwsh.exe version on this machine is:

7.6.1

2. Replaying Codex sandbox env works in a normal child process

I extracted a real Codex sandbox request JSON from:

C:\Users\Administrator\.codex\.sandbox\requests\request-cc3f6e10eba310db9a9eb6e1beb7c306.json

Using the same:

  • cwd
  • env_map
  • executable path
  • PowerShell arguments

I replayed powershell.exe in a normal child process, and it worked.

That suggests the problem is not caused by:

  • PATH
  • PSModulePath
  • current working directory
  • PowerShell profile
  • the command text itself

It points more specifically to the Codex runner / sandbox token / host environment.

3. AppLocker-related system components appear present and healthy

Checked locally:

  • C:\Windows\System32\appidapi.dll exists
  • C:\Windows\System32\wldp.dll exists
  • AppIDSvc is running
  • AppLockerFltr is running

Normal PowerShell also reports:

  • LanguageMode: FullLanguage

Execution policy is not obviously abnormal.

4. Codex logs show shell_command uses Windows PowerShell through the command runner

Observed in local files:

  • C:\Users\Administrator\.codex\.sandbox\sandbox.log
  • C:\Users\Administrator\.codex\archived_sessions\rollout-2026-04-24T19-02-17-019dbf27-9db1-7963-9dd0-8c8d732d2f97.jsonl

Examples show the runner invoking:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command ...

and the failing runner binary observed in logs is:

C:\Users\Administrator\.codex\.sandbox-bin\codex-command-runner-0.125.0-alpha.3.exe

Additional notes

I also changed the local integrated terminal preference from powershell to pwsh, but that did not fix shell_command.

This suggests that:

  • integrated terminal shell preference
  • shell_command backend shell host

are not controlled by the same setting.

Local artifacts / evidence

Relevant local files:

  • C:\Users\Administrator\.codex\.sandbox\sandbox.log
  • C:\Users\Administrator\.codex\.sandbox\requests\request-cc3f6e10eba310db9a9eb6e1beb7c306.json
  • C:\Users\Administrator\.codex\archived_sessions\rollout-2026-04-24T19-02-17-019dbf27-9db1-7963-9dd0-8c8d732d2f97.jsonl

Relevant log pattern:

powershell.exe -NoProfile -NonInteractive -Command ...

and repeated failures around:

InitialSessionState
GetSaferPolicy
GetAppLockerPolicy
Win32Exception (126)

Request

Please investigate whether the Windows shell_command runner / sandbox host is creating a token or process environment that breaks PowerShell's AppLocker / Safer policy initialization path.

From local testing, the issue does not reproduce when the same executable, env, cwd, and command are launched outside the Codex runner.

github-actions[bot] contributor · 2 months ago

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

  • #19100
  • #19629
  • #19171
  • #18937
  • #19952

Powered by Codex Action

VentureDuan · 2 months ago

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)

VentureDuan · 2 months ago

Right now, my Codex can't use PowerShell to retrieve file contents or execute the corresponding commands, which is really frustrating. I have no choice but to fall back to using node_repl to retrieve file contents. I hope Codex fixes this issue as soon as possible.

VentureDuan · 2 months ago

Codex, I can’t live without you—please fix this as soon as possible. Let me know if you need any other information; I can reliably reproduce the issue on my machine right now.

VentureDuan · 2 months ago

<img width="238" height="233" alt="Image" src="https://github.com/user-attachments/assets/e1d192c3-4d85-491e-81ec-2935c1ed8063" />

VentureDuan · 2 months ago

I can't use PowerShell with either the Codex app or the Codex CLI.

VentureDuan · 2 months ago

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

VentureDuan · 2 months ago

I have also reported this issue on CodexApp. The issue ID is: 019ddc8d-ff64-7321-9c26-88695c29e5ce