Repository navigation
Description
Environment
- Codex CLI and Windows command runner 0.171.0
- Windows 11 x64, version 26H2, OS build 26300.10075
- CPython 3.13.5 x64 from python.org
- Windows
elevatedsandbox with a workspace-write permission profile, network enabled, and the default private desktop - Both test paths run in Windows Session 1 with a restricted token and
TokenIsAppContainer=0
Minimal reproduction
Run this through a sandboxed Codex PowerShell command in a writable workspace. Set $base to the actual CPython 3.13.5 executable. Use an unused path for the empty venv. No third-party packages are required.
$base = 'C:\Path\To\Python313\python.exe'
& $base -B -m venv --without-pip .\.venv-repro
@'
import ctypes, os, subprocess, sys
from pathlib import Path
ctypes.windll.kernel32.SetErrorMode(3)
launcher = str(Path('.venv-repro/Scripts/python.exe').resolve())
args = [launcher, '-B', '-X', 'faulthandler', '-c',
'import sys, platform; print(sys.prefix, flush=True); print(platform.system())']
p = subprocess.run(args)
print(f'venv launcher: 0x{p.returncode & 0xffffffff:08x}', flush=True)
env = os.environ | {'__PYVENV_LAUNCHER__': launcher}
p = subprocess.run(args, executable=sys.executable, env=env)
print(f'direct CPython with same venv: 0x{p.returncode & 0xffffffff:08x}', flush=True)
'@ | & $base -B -Expected behavior is that both commands print the venv prefix and Windows, then exit 0. In the sandbox, the venv launcher case prints the prefix and crashes inside platform._wmi_query with 0xc06d007e. The direct CPython control uses the same venv prefix and arguments, prints Windows, and exits 0. The venv launcher also works from a regular Windows terminal outside Codex.
Debugger evidence
- CDB followed the redirector into its
python.exechild. The first failing call observed waswin32u!NtGdiInit2, which returned zero in that child and a nonzero value in the direct-CPython control. gdi32full!GdiDllInitializethen returned0xc0000001in the redirector child, andUSER32!UserClientDllInitializereturnedFALSE.- The MSVC delay-load exception record identifies
_wmi.pydrequestingCoInitializeExfromole32.dll.DelayLoadInfo.dwLastErrorwas1114(ERROR_DLL_INIT_FAILED). The debugger recorded the systemole32.dllbeing mapped before initialization failed. import _ctypesalso fails in the redirector child with a DLL initialization error, and succeeds in the direct-CPython control.
The direct-launch control also loads the existing venv's site-packages and leaves the Windows sandbox mode in place. The reason NtGdiInit2 returns zero on the redirector path is still unknown. Could the Windows sandbox maintainers check this child-launch path?
Related reports #37722 and #46412 describe USER32 initialization failures with Session 0 launchers. This reproduction runs in Session 1 and reaches Python code before the first lazy load of the affected DLLs.
Activity