Repository navigation
Description
What version of Codex CLI is running?
codex-cli 0.163.0
What platform is your computer?
Windows 11 ARM64, build 10.0.26200 (also reported on Windows x64)
What issue are you seeing?
Inside the Windows unelevated sandbox (workspace-write), ninja hangs forever on its first build step. The step's command runs and exits, but ninja never notices, so every ninja-based build hangs (CMake's Ninja generator, Meson, etc.) with no error. The process sits at ~0 CPU with no child processes until it is killed. The same build completes instantly outside the sandbox.
Minimal repro, with no project code needed:
# build.ninja
rule r
command = cmd /c echo hi
build out: rcodex sandbox -c windows.sandbox="unelevated" -c sandbox_mode="workspace-write" -- ninja
ninja 1.13.2 (the official arm64 build, and the copy bundled with Visual Studio) prints [0/1] cmd /c echo hi and hi, then never returns. It does the same with command = cmd /c exit 0, command = whoami.exe (no cmd), and pool = console.
Root cause
ninja learns that a step has finished when the write end of a per-step named pipe closes (src/subprocess-win32.cc, Subprocess::SetupPipe). It creates the pipe with CreateNamedPipeA(…, NULL) (default security), registers it with an I/O completion port, then opens the write end itself with CreateFileA(pipe_name, GENERIC_WRITE, …) to give to the child.
Inside the sandbox, that CreateFileA fails with ERROR_ACCESS_DENIED. The process cannot open a pipe it has just created. I replayed ninja's exact sequence in a standalone program:
| step | outside sandbox | inside sandbox |
|---|---|---|
CreateNamedPipe (default SA) |
ok | ok |
CreateIoCompletionPort / overlapped ConnectNamedPipe |
ok / pending | ok / pending |
CreateFile(pipe, GENERIC_WRITE) |
ok | ERROR_ACCESS_DENIED |
| child process runs and exits | yes | yes (exit 1: invalid stdout) |
| completion port reports the pipe broken (step done) | yes | never |
ninja doesn't check that CreateFileA result. INVALID_HANDLE_VALUE equals the GetCurrentProcess() pseudo-handle, so the following DuplicateHandle succeeds, and the child gets a bogus stdout. Nothing ever connects to the pipe, so ninja waits on the completion port forever. (I reported the missing check to ninja as ninja-build/ninja#2868. Fixing it would turn the hang into an error, but the open would still fail.)
Explicit pipe DACLs show it's the restricted token's access check:
| pipe DACL (SDDL) | CreateFile inside sandbox |
|---|---|
| default | ERROR_ACCESS_DENIED |
D:(A;;GA;;;OW) |
ERROR_ACCESS_DENIED |
D:(A;;GA;;;OW)(A;;GA;;;RC) |
ERROR_ACCESS_DENIED |
D:(A;;GA;;;WD) |
ok |
This is the same underlying problem as #19791 (Python ≥ 3.13 mkdir(…, 0o700) / tempfile.mkdtemp() directories are unusable in the sandbox). Objects the sandboxed process creates get a DACL its own restricting SIDs can't pass. #23017 (named-pipe MCP servers failing with WinError 5 in CreateNamedPipe/PipeListener) looks like the same mechanism.
It probably also affects MSBuild's parallel build (/m), whose worker nodes talk over named pipes. In our sandbox a --parallel MSBuild build failed with no diagnostic, while a serial build succeeded. I haven't verified that this is the same cause.
What steps can reproduce the bug?
- On native Windows, install ninja (e.g.
winget install Ninja-build.Ninja). - In an empty directory, write the 2-line
build.ninjaabove. - Run
codex sandbox -c windows.sandbox="unelevated" -c sandbox_mode="workspace-write" -- ninja.
What is the expected behavior?
Processes inside the sandbox can open the client end of a named pipe they created, as they can outside it. ninja and other tools built on the same pipe-and-completion-port pattern then work in workspace-write.
Additional information
Suggested fix: give the restricted token a TokenDefaultDacl that includes an ACE for one of its restricting SIDs (e.g. the sandbox capability SID). Then objects the sandboxed process creates with default security, such as pipes, events and sections, are usable by the sandboxed process and its children. Today the only workaround is danger-full-access, which removes the sandbox entirely, or running builds outside Codex.
Activity