Repository navigation
Description
What version of Codex CLI is running?
codex-cli 0.125.0
Platform
Native Windows, PowerShell shell tool, workspace-write sandbox. Workspace is on D:\Data\backlog-docgen.
Python/test stack:
- Python
3.14.3(MSC v.1944 64 bit (AMD64)) - pytest
9.0.2 - pytest-xdist
3.8.0 - pytest configured with
-n auto --dist loadfile
Issue
Inside the Codex Windows sandbox, pytest-xdist fails when pytest creates temporary directories using its default private directory mode (0o700). The failures are Windows PermissionError: [WinError 5] Access is denied when pytest/xdist tries to reopen or scan temp directories that the same test run just created.
This looks like an interaction between:
- Python/pytest creating temp directories with restrictive permissions (
mode=0o700), includingtmp_path,tmp_path_factory, and xdist worker basetemps. - Codex's Windows sandbox/restricted token/ACL model not being able to access those owner-only directories after creation.
- xdist multiplying the problem because controller and workers exchange temp roots such as
pytest-of-shaun\pytest-0\popen-gw*.
Minimal reproduction shape
In a Python project with pytest-xdist installed and default xdist config:
[tool.pytest.ini_options]
addopts = """
-ra
-q
-n auto
--dist loadfile
--maxfail=3
--tb=short
--no-header
"""Run inside the Codex Windows sandbox:
uv run pytest tests/test_active_backlogs_current_schema.py -qRepresentative failures seen while investigating:
INTERNALERROR> PermissionError: [WinError 5] Access is denied: 'C:\Users\shaun\AppData\Local\Temp\pytest-of-shaun'
After forcing temp roots into the workspace with PYTEST_DEBUG_TEMPROOT, failures moved to workspace-local pytest dirs:
INTERNALERROR> PermissionError: [WinError 5] Access is denied: 'D:\Data\backlog-docgen\.pytest-tmp\run-...\pytest-of-shaun'
With xdist worker basetemps:
PermissionError: [WinError 5] Access is denied: 'D:\Data\backlog-docgen\.pytest-tmp\run-...\pytest-of-shaun\pytest-0\popen-gw1'
With tests that use tmp_path/tmp_path_factory:
PermissionError: [WinError 5] Access is denied: 'D:\Data\backlog-docgen\.pytest-tmp\run-...\pytest-of-shaun\pytest-0\test_import_no_changes0\test-backlog'
With app code using tempfile.TemporaryDirectory(), the underlying PermissionError was converted by the FastAPI app into 403 responses.
Workarounds tested
These did not solve the underlying issue:
- serial pytest only (
-n 0) avoids xdist but is not practical for larger suites - fixed
--basetemp=pytest-temp/--basetemp=tmp_pytesteventually becomes inaccessible after aborted or repeated runs PYTEST_DEBUG_TEMPROOTalone keeps dirs in the workspace but still creates0o700dirs that the sandbox cannot reopen- unique per-run temp roots avoid name reuse but still fail once pytest/xdist creates nested private dirs
The only successful in-repo workaround so far is very invasive: monkeypatching temp directory creation during tests so directories under the pytest temp root use sandbox-readable permissions, and patching xdist so workers do not receive controller-created fixed popen-gw* basetemps. That required touching Path.mkdir, os.mkdir, TMP/TEMP/TMPDIR, PYTEST_DEBUG_TEMPROOT, and xdist.workermanage.WorkerController.setup from tests/conftest.py.
That workaround is a strong smell; normal Python projects should not need to patch os.mkdir to run pytest in Codex.
Related issues found
I searched openai/codex issues for:
pytest xdist PermissionError 0o700 Windows sandboxpytest-of-shaun popen-gw PermissionError Windows sandboxPYTEST_DEBUG_TEMPROOT pytest-of-shaun Windows sandbox0o700 Windows sandbox ACL Python tempfile
I did not find this exact issue.
Closest related Codex issues I found:
- v0.107.0 Windows Sandbox ACL Failure (Error 5) and Unintended Permission Pollution on User Home Directory #13378 - Windows sandbox ACL failure / permission pollution on user home directory
- Windows sandbox refresh fails for most shell_command invocations before execution #15809 - Windows sandbox refresh failures before command execution
- Allow Windows users to run Codex in "no sandbox" mode and explicitly approve/deny commands #18005 - request for explicit no-sandbox mode on Windows
- Windows sandboxed shell commands fail with CreateRestrictedToken failed: 87 even with [windows] sandbox = "unelevated" #18451 - Windows sandboxed shell commands fail under restricted token setup
Related pytest issue:
- Allow to change permissions of temp directories created with tmp_path pytest-dev/pytest#10679 - pytest hardcodes
0o700permissions for tmp dirs and does not expose a way to override them
Question
Is this expected behavior for the Windows sandbox? If yes, is there an intended way for common Python test tooling that creates 0o700 temp dirs (pytest/tmp_path/tmp_path_factory/tempfile + pytest-xdist workers) to run inside the sandbox without disabling xdist or broadening execution outside the sandbox?
From the user side, this looks like a very common combination: native Windows + Codex CLI sandbox + Python 3.14 + pytest + pytest-xdist. The expected behavior is that temp directories created by a sandboxed process remain accessible to that process and its sandboxed child worker processes for the duration of the test run.
Activity
JeppeKlitgaard commentedon Jul 16, 2026
This is an really frustrating issue to run into. I believe this is also related: #9757
grsrzxgvmpg commentedon Sep 26, 2026
Additional data point with the underlying mechanism, plus a narrower workaround than patching
os.mkdirfromconftest.py.Environment: native Windows 11,
codex-cli 0.153.4,[windows] sandbox = "unelevated",workspace-write, Python 3.13.7 (so not only 3.14), pytest 9.1.0.Mechanism. On Windows, Python ≥ 3.13 implements
os.mkdir(path, 0o700)(alsotempfile.mkdtemp/TemporaryDirectory) by writing a protected DACL containing onlyOWNER RIGHTS,SYSTEMandAdministrators, instead of inheriting the parent's ACL. The parent ACL is what grantsCodexSandboxUsersand the per-sandbox SIDs. The unelevated sandbox's restricted token needs those restricting SIDs to pass the access check, so the new directory is unusable even by the sandboxed process that just created it. Python 3.11 still inherits the parent ACL and is unaffected. A directory created with0o700outside the sandbox, e.g.%TEMP%\pytest-of-<user>from a normal pytest run, poisons later sandboxed runs the same way.Minimal repro without pytest (run from any workspace dir):
Confirming the earlier report:
--basetemp=<workspace dir>andPYTEST_DEBUG_TEMPROOTdo not help. pytest still creates the basetemp and every numbered dir withmode=0o700.Narrow workaround that works here: a small pytest plugin, installed with a
pytest11entry point, that downgrades0o700→ default mode only while pytest itself creates its dirs, by wrappingTempPathFactory.getbasetemp,TempPathFactory.mktempandcacheprovider._make_cachedir. The patch must be re-entrant, becausemktempcallsgetbasetemp. Code under test is untouched, and its own0o700dirs stay protected.Results inside
codex sandbox(workspace-write) after one-time removal of the pre-poisonedpytest-of-<user>:tmp_path+tmp_path_factorytest, default temp root (run twice)tmp_pathheavilyThe remaining 10 failures are app code calling
tempfile.mkdtemp(), which is the same mechanism outside pytest's control. I haven't tested xdist worker basetemps (popen-gw*); they come fromgetbasetempon the controller, so I'd expect them to be covered, but that is unverified.A durable fix probably belongs on the sandbox side. The goal is for directories a sandboxed process creates with an explicit owner-only DACL to remain usable by that same restricted token, since
0o700is now common in Python tooling.pytest-dev/pytest#10679(hardcoded0o700) is the pytest-side counterpart.ljx719476856li commentedon Oct 8, 2026
Related reproduction with desktop package 26.1002.7124.0, bundled codex-cli 0.162.0-alpha.2, Windows build 10.0.26200.9457 and Python 3.12.10. The current desktop shell uses a sandbox-specific temporary directory shaped like %LOCALAPPDATA%\Packages\sandbox.{GUID}\AC\Temp. We have not established that its implementation is identical to the original report's restricted-token backend.
Minimal Python reproduction inside the managed desktop shell:
Directory creation succeeds, but writing probe.txt fails with PermissionError / WinError 5. Cleanup also fails with access denied.
Controls on this installation:
No pytest or xdist dependency is needed for this reproduction. The independent runtime-sharing-violation report is #51932; we have not demonstrated a causal connection between the two errors.
jm2 commentedon Oct 26, 2026
Confirming this is still present on codex-cli 0.163.0 (unelevated sandbox,
workspace-write,windows.sandbox="unelevated"), Windows 11 ARM64 build 26200, Python 3.14.7 arm64. It's not limited to x64 or older builds.Minimal repro without pytest, run with
codex sandbox -c windows.sandbox="unelevated" -c sandbox_mode="workspace-write" -- python repro.pyfrom a workspace dir:os.mkdir(p), then write a file in itos.mkdir(p, 0o700), then write a file in itPermissionError: [Errno 13]tempfile.mkdtemp(), then write a file in itPermissionError: [Errno 13]In our case it blocks every test that uses
tempfile.mkdtemp()at fixture setup, before any assertion runs.This isn't specific to
0o700or to Python. Any kernel object the sandboxed process creates with a DACL that doesn't name one of the token's restricting SIDs is unusable by that same process. I tested named pipes with explicit security descriptors. The sandboxed process creates the pipe, then opens its client end withCreateFileW(GENERIC_WRITE):NULLsecurity attributes)D:(A;;GA;;;OW)(owner rights only)D:(A;;GA;;;OW)(A;;GA;;;RC)(+ RESTRICTED)D:(A;;GA;;;WD)(Everyone)So a protected owner-only ACL (Python ≥ 3.13
mkdir(…, 0o700)) and the token's own default DACL both fail the restricted-SID pass of the access check. The silentninjabuild hang is a separate symptom of this, filed as #57122.Suggested fix: make objects created by a sandboxed process accessible to its restricting SIDs. For example, set the restricted token's
TokenDefaultDaclto include an ACE for the sandbox's capability SID. Ideally, also make the restricting-SID set satisfiable byOWNER RIGHTS/ creator-owner ACEs, so owner-only DACLs written by the sandboxed process itself still work. As the earlier comments show, per-tool workarounds (pytest plugins, patchingos.mkdir) don't scale.test(harness): tool tests' temp dirs without mkdtemp's Windows DACL too
pskraemer11 commentedon Nov 21, 2026
Additional confirmation (single-process pytest, no xdist required)
Summary
This issue also reproduces without pytest-xdist, for plain single-process pytest: the Codex Windows sandbox cannot access Pytest's
tmp_pathdirectories (created withmode=0o700), failing withPermissionError: [WinError 5]on the first access, while the same test run succeeds outside the sandbox.Environment
Reproduction
A minimal suite with a single test that uses
tmp_path(e.g. writes a file) fails inside the sandbox withPermissionError: [WinError 5]when the test first touches the freshly created temp directory; the identical run in a regular PowerShell is green.Isolated cause
Reproduced with plain Python, without Pytest:
Path.mkdir()without amode→ list/write/delete works in the sandbox.Path.mkdir(mode=0o700)→PermissionError [WinError 5]afterwards on listing, writing, and deleting.The ACL of such a directory shows a protected DACL with
OWNER RIGHTS,SYSTEM, andAdministrators(FullControl). The sandbox token carriesAdministratorsas deny-only in its token information and has no allow ACE that applies after the DACL is replaced. Parent directories, by contrast, keep inherited ACLs with full user control.Responsibilities
Pytest side (not a bug): Pytest creates
tmp_pathand basetemp directories withmode=0o700as a secure default. That is intentional behavior, not a Pytest defect. Whether that restriction is even required on Windows is disputable at most.Codex side (fix needed here): A process that is allowed to create a folder with restrictive permissions can afterwards no longer access it itself, because the ACL leaves no effective allow ACE for the sandbox token after the DACL is replaced. Standard Pytest suites are therefore unusable inside the sandbox even though they work system-wide, and users cannot configure this per repository. The fix belongs on the sandbox side (token/ACL handling, or broadening the sandbox write scope).
Workaround (not a solution)
Per repository, a
tests/conftest.pythat overridestmp_path: root undertests/artifacts/(git-ignored), one folder per test created with.mkdir()without amode, cleanup withshutil.rmtree. This has to be maintained per repository and does not address the sandbox interaction itself.