Windows Codex Desktop repeatedly leaves thousands of __PSScriptPolicyTest_*.ps1 files in %TEMP%

Open 💬 0 comments Opened Jul 15, 2026 by k7631159

Summary

On Windows, Codex Desktop repeatedly leaves PowerShell AppLocker/WDAC policy-detection files named __PSScriptPolicyTest_<random>.ps1 in %LOCALAPPDATA%\Temp.

PowerShell normally removes these files immediately in a finally block. On this machine, fully closing Codex Desktop stops new files from appearing; reopening Codex makes them appear again, with the rate increasing when Codex shell tools are active.

This produced 23,962 orphaned files in about eight days. Each file is only 60 bytes, so disk capacity is not the main concern; the unbounded file-count growth and repeated failed cleanup are.

Observed behavior

  • Inventory on 2026-07-15: 23,962 matching .ps1 files.
  • Earliest creation date: 2026-07-07.
  • File content:

``powershell
# PowerShell test file to determine AppLocker lockdown mode
``

  • During a controlled test, one Codex shell invocation increased the count by 5; another invocation increased it by another 5.
  • While the same PowerShell process remained alive for five seconds, the count did not increase.
  • A normal independent pwsh startup completed without leaving a matching file.
  • Fully closing Codex Desktop stopped the growth.
  • Reopening Codex Desktop resumed the growth. Idle frequency was lower than during active shell use.
  • The behavior persisted across multiple Windows reboots, including a reboot on 2026-07-15.
  • Only the .ps1 policy-test files were observed accumulating; matching .psm1 files were not observed accumulating.

Environment

  • Windows Codex Desktop
  • PowerShell 7.6.3 (MSIX/WindowsApps installation)
  • pwsh.exe: C:\Program Files\WindowsApps\Microsoft.PowerShell_7.6.3.0_x64__8wekyb3d8bbwe\pwsh.exe
  • Language mode: FullLanguage
  • Execution policy: LocalMachine = RemoteSigned; all other scopes Undefined
  • __PSLockdownPolicy is not set
  • Relevant AppLocker event logs are enabled but contain zero records
  • No evidence that AppLocker or WDAC enforcement is actually enabled
  • Codex Feedback diagnostics trace/task ID: 019f652f-2a73-7b30-8d73-0d9063d1cdb4

Expected behavior

Codex shell execution should allow PowerShell's temporary lockdown-policy test files to be removed, or perform a bounded retry/cleanup after the shell process exits. Keeping Codex open should not cause unbounded growth in %TEMP%.

PowerShell implementation details

This is an official PowerShell policy-detection file, not user code:

The fact that normal pwsh startup cleans up successfully, while Codex-triggered shell activity leaves .ps1 files and closing Codex stops the growth, suggests a Codex Desktop shell-bridge/sandbox interaction. One plausible mechanism is that the .ps1 remains open or inaccessible exactly when PowerShell performs its one-shot cleanup. This mechanism is not yet proven.

Requested investigation/fix

Please investigate the Windows PowerShell execution bridge and sandbox lifecycle around policy detection, particularly whether:

  1. a bridge/sandbox/security component briefly keeps the test .ps1 open during PowerShell's finally cleanup;
  2. helper PowerShell processes are terminated before normal cleanup completes; or
  3. the bridge can retry removal of these known temporary test files after child-process exit.

I can provide additional diagnostics from the Feedback trace above if needed.

View original on GitHub ↗