Sandboxed pytest stalls when run via make or redirected output, but direct foreground pytest works

Resolved 💬 2 comments Opened Apr 4, 2026 by vshikhar95 Closed Apr 4, 2026
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

Summary

I found a narrower sandbox-related pytest reproduction than the existing timeout reports.

In my environment, Python/pytest itself is not generally broken inside the Codex sandbox. The failure mode is more specific:

  • works inside sandbox:
  • source .venv/bin/activate && python -m pytest -vv
  • stalls inside sandbox:
  • make test-backend where the recipe is just python -m pytest -vv
  • python -m pytest -vv > out.txt 2>&1
  • python -m pytest -vv -s > out.txt 2>&1
  • works outside sandbox:
  • make preflight
  • make test-backend

So the issue seems to be triggered when pytest is not attached to the live foreground exec output path inside the sandbox, rather than pytest being universally sandbox-incompatible.

Environment

  • Codex CLI in sandbox mode
  • Ubuntu Linux
  • Python 3.12.3
  • pytest 9.0.2
  • bubblewrap-based sandbox (Codex default on Linux)

Reproduction

In a repo with a passing backend test suite:

Works

source .venv/bin/activate && python -m pytest -vv

This streams progress normally and finishes.

Stalls

make test-backend

Where test-backend is effectively:

test-backend:
	.venv/bin/python -m pytest -vv

The command starts normally, prints the pytest session header and first test line, then stops making visible progress in the sandbox.

Also stalls

source .venv/bin/activate && python -m pytest -vv > /tmp/out.txt 2>&1
source .venv/bin/activate && python -m pytest -vv -s > /tmp/out.txt 2>&1

Both timed out in the sandbox after reaching the first test line.

What I checked

  • tests/test_backup.py -vv by itself passes in about 1 second inside the sandbox.
  • full python -m pytest -vv passes inside the sandbox when run directly in the foreground.
  • a trivial make recipe running a streaming Python script works fine in the sandbox, so this is not just “make is broken in sandbox”.
  • the problematic combination seems to be: pytest + sandbox + non-foreground/non-live-output execution path.

Why this seems distinct from the broader timeout issue

The existing timeout reports made it look like pytest itself was generally broken in sandbox.

This reproduction suggests the bug is narrower:

  • direct foreground pytest can work
  • pytest stalls when launched through make or when stdout/stderr are redirected away from the live foreground session

That points more toward sandboxed exec/session/output handling than pytest compatibility in general.

Request

Can you confirm whether this is a known Codex sandbox/PTY/output-path issue?

View original on GitHub ↗

2 Comments

github-actions[bot] contributor · 4 months ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #15053

Powered by Codex Action

vshikhar95 · 4 months ago

Closing as a duplicate of #15053. After further investigation, this narrower pytest reproduction appears to be another manifestation of the sandbox asyncio/anyio self-pipe wakeup bug described there. In this case, the sandboxed pytest environment includes anyio, and the observed stalls/timeouts are consistent with that underlying issue.