Skip to content

Windows permissions issue: Codex agent cannot run pytest if tests write temp files #9757

Closed as not planned

Description

@emretezel

What version of Codex is running?

Latest extension for VS Code

What subscription do you have?

Plus

Which model were you using?

gpt-5.1-codex

What platform is your computer?

Windows 11

What terminal emulator and version are you using (if applicable)?

VS Code

What issue are you seeing?

Hi all — I’m running into a persistent issue with the OpenAI Codex extension in VS Code on Windows when using agent mode to run my Python test suite.
What I’m trying to do
I have an AGENTS.md instruction that asks Codex to run my pytest suite after changes (as part of a normal “edit -> run tests” workflow).
Some tests create temporary files/folders at runtime (e.g. writing small files, creating temp dirs, etc.).
The problem
When Codex agent tries to execute pytest, it hangs or fails due to drive permission issues when creating/writing temp files.
What’s confusing is:
If I run the same tests manually from VS Code (Test Explorer “Run All”) everything works normally.
The same repo and same tests have no issues when run manually.
What I tried (all failed)
Temp folder inside repo (e.g. ./tmp_test_artifacts/)
Temp folder under my user profile (e.g. %USERPROFILE%\tmp...)
Creating a brand new temp folder for each run
Giving Codex explicit instructions to use a specific temp path
Ensuring folders exist beforehand
Codex still seems to hit permission issues (or gets stuck) when it runs the tests.
How Codex is running tests
From the Codex logs / terminal it appears to run something like:
conda run -n <env_name> python -m pytest
(sometimes via a shell wrapper depending on environment)
Expected behavior
Codex agent should be able to run pytest successfully, including tests that create temp files, same as when I run tests manually inside VS Code.
Questions
Is this a known issue with Codex agent execution context on Windows (permissions / sandboxing / different user)?
Is there a recommended temp directory strategy for Codex on Windows (e.g. force %TEMP%, tempfile.gettempdir(), etc.)?
Are there known settings / workarounds for:
Running Codex under a different shell (PowerShell vs cmd)
Forcing a different working directory
Ensuring permissions match normal VS Code test execution?
Happy to share more details (exact error output + minimal repro) if needed.
Thanks!

What steps can reproduce the bug?

Ask codex to run pytest suite where a test file needs to write a temp file to drive.

What is the expected behavior?

No response

Additional information

No response

Activity

  1. added
    bug
    on Jan 23, 2026
  2. added
    extension
    windows-os
    sandbox
    on Jan 23, 2026
  3. emretezel commented on Jan 23, 2026

    @emretezel
    Author

    Update (temp path detail):
    By default, my pytest temp artifacts are being created under Windows temp, e.g.:
    %TEMP%\pytest-of-\pytest-...
    This works perfectly when I run tests manually inside VS Code (Test Explorer / normal terminal).
    However, when Codex agent runs pytest, it seems to run inside a sandbox / different execution context where writing to this default pytest temp directory fails (permission / access issue), so the suite cannot complete.
    I also tried overriding the temp location to:
    inside the repo
    inside %USERPROFILE%
    a newly created folder per run
    …but the Codex extension environment still fails whenever the tests attempt to create/write temp files.

  4. etraut-openai commented on Jan 23, 2026

    @etraut-openai
    Contributor

    Yes, if you are running tools or scripts that attempt to write to locations that are not permitted by the sandbox policy, they will fail.

    You'll need to determine the underlying cause and either modify the configuration of the tool to avoid such writes or modify the sandbox policy to allow writes to the necessary location. You can add a sandbox_workspace_write.writable_roots array in your config.toml. See this documentation for a full config key reference.

  5. emretezel commented on Jan 26, 2026

    @emretezel
    Author

    Thanks — that makes sense.
    The confusing part is that it also fails when the tests try to create temp files inside the project workspace itself (not just under %TEMP%). I tested writing to paths like ./tmp/… under the repo root and still hit the same permission / access failure when Codex runs pytest.
    Is there any known issue with the way Codex executes commands on Windows — e.g. via:
    conda run -n python -m pytest
    — that results in a different sandbox context / working directory / permissions compared to running tests manually in VS Code?
    If so, is the recommended fix to add the repo root to sandbox_workspace_write.writable_roots, or is there another setting to ensure writes within the workspace are allowed?

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

    bugextensionsandboxwindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions