Windows sandbox blocks pytest-xdist temp dirs created with Python 3.14/pytest 0o700 permissions
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 -q
Representative 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:
- https://github.com/openai/codex/issues/13378 - Windows sandbox ACL failure / permission pollution on user home directory
- https://github.com/openai/codex/issues/15809 - Windows sandbox refresh failures before command execution
- https://github.com/openai/codex/issues/18005 - request for explicit no-sandbox mode on Windows
- https://github.com/openai/codex/issues/18451 - Windows sandboxed shell commands fail under restricted token setup
Related pytest issue:
- https://github.com/pytest-dev/pytest/issues/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.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗