Skip to content

Windows elevated sandbox: Python 3.13.5 venv child crashes in GDI initialization (0xc06d007e) #62976

Open

Description

@fufuzhou

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 elevated sandbox 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.exe child. The first failing call observed was win32u!NtGdiInit2, which returned zero in that child and a nonzero value in the direct-CPython control.
  • gdi32full!GdiDllInitialize then returned 0xc0000001 in the redirector child, and USER32!UserClientDllInitialize returned FALSE.
  • The MSVC delay-load exception record identifies _wmi.pyd requesting CoInitializeEx from ole32.dll. DelayLoadInfo.dwLastError was 1114 (ERROR_DLL_INIT_FAILED). The debugger recorded the system ole32.dll being mapped before initialization failed.
  • import _ctypes also 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

  1. added
    bugSomething isn't working
    CLIIssues related to the Codex CLI
    windows-osIssues related to Codex on Windows systems
    sandboxIssues related to permissions or sandboxing
    on Nov 21, 2026
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

    CLIIssues related to the Codex CLIbugSomething isn't workingsandboxIssues related to permissions or sandboxingwindows-osIssues related to Codex on Windows systems

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions