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

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

  1. Is this a known issue with Codex agent execution context on Windows (permissions / sandboxing / different user)?

  2. Is there a recommended temp directory strategy for Codex on Windows (e.g. force %TEMP%, tempfile.gettempdir(), etc.)?

  3. 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!

1 Like

Hi

Thanks again for all the detailed insights you’ve shared. I’m really fascinated by how your systems handle adaptation, pattern validation, and the separation between behavioral changes and factual rigor.

I’m a future OpenAI tester, and I’m very interested in exploring, testing, and understanding exactly how these models work: how patterns are created, how memory and signals interact, and how adaptation occurs. I’d love to study similar projects, analyze the code, and see the concepts in action.

If you have any GitHub repositories or example projects you can share, I’d be eager to look into them and learn from them.

Looking forward to your guidance!

Best

I saw your post about the Windows permissions issue where Codex agents cannot run pytest if tests write temp files. I’m curious:

Have you found a reliable workaround for Windows users, or is this still a blocker?

Does this problem happen only with certain Python versions or Windows configurations?

In general, how do you recommend setting up a Windows environment for testing Codex agents without hitting permission issues?

Thanks for any guidance!

Issues are reported via the GitHub OpenAI Codex repository

https://github.com/openai/codex

https://github.com/openai/codex/issues

I took a quick glance at the titles of the issues for Windows and saw none noting temp file.

https://github.com/openai/codex/issues?q=is%3Aissue%20state%3Aopen%20label%3Awindows-os&page=1

You should report this as a new issue.


Have you asked the AI in the project about this? Sometimes AI are able to do a decent job of providing an answer but then at times they may hallucinate an answer so you will have to see if it works.

I also find that asking for “best practices” at times will give the “best practice” which tends to algin with the training data and thus what the AI will often give and try to use in most cases.


You noted " AGENTS.md instruction", is that really the best place to add this? The prompt might be correct but not being included with your workflow? (Rhetorical questions)

1 Like

Hi and welcome to the community!

I have run into this permission error as well. In my case, it was resolved either by preventing pytest from creating and using those directories or by switching the cache to a writable path.

You can avoid the issue entirely by disabling pytest’s cache plugin via a pytest.ini file. This prevents creation of the .pytest_cache directory and the pytest-cache-files-* temp directories. The tradeoff is that cached information such as lastfailed and collection node IDs is no longer available. You can also exclude those directories from test collection.

[pytest]
addopts = -p no:cacheprovider
norecursedirs = pytest-cache-files-*

For small projects this is usually fine. Test runs may be slightly slower, and information like last or first failed tests is lost. Some plugins may also rely on the cache, and certain debugging details may no longer be available.

If you do need the cache data, you can instead point the cache to a writable directory. In my case, Codex sometimes required full access for the session.

[pytest]
cache_dir = C:\Users\YOUR_USERNAME\AppData\Local\pytest_cache

I have not used pytest in a while, so I cannot say with certainty which warnings are expected and which may be specific to the interaction with Codex. I wouldn’t be at all surprised if it was a Windows bug.

Hope this helps.

1 Like

Update (temp path detail):
By default, my pytest temp artifacts are being created under Windows temp, e.g.:

%TEMP%\pytest-of-<user>\pytest-<n>\...

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.

1 Like

Hi

I’m really interested in exploring similar projects and understanding how Codex handles testing, caching, and temp files on Windows.

Would it be possible to share any GitHub repos or resources that illustrate these concepts?

I’m studying and trying to learn more about testing and adaptive AI behavior.

Thank you for any guidance!