Repository navigation
Description
What version of Codex CLI is running?
codex-cli 0.115.0
What subscription do you have?
Team
Which model were you using?
gpt-5.4-medium,gpt-5.4-xhigh
What platform is your computer?
Linux 6.6.87.2-microsoft-standard-WSL2 x86_64 unknown
What terminal emulator and version are you using (if applicable)?
Google Antigravity
What issue are you seeing?
Summary
I found what looks like a Codex sandbox issue.
Inside the Codex sandbox, Python async code that relies on cross-thread event loop wakeups
can hang or time out. This affects:
asyncio.call_soon_threadsafe(...)asyncio.to_thread(...)loop.run_in_executor(None, ...)anyio.to_thread.run_sync(...)anyio.Path(...).exists()and similar helpers that offload sync work to threads
Outside the sandbox, the same commands complete successfully.
Environment
- Codex CLI sandbox
- Reproduced on March 18, 2026
- Project Python:
.venv/bin/python3 - Python version:
3.13 pytest:9.0.2pytest-asyncio:1.3.0anyio:4.12.1
What steps can reproduce the bug?
Reproduction
I used this command in a repo only as a probe harness:
.venv/bin/python3 scripts/probe_async_executor.py --timeout 2Inside the sandbox, the probe showed this pattern:
- asyncio.to_thread(...): timeout
- loop.run_in_executor(None, ...): timeout
- anyio.to_thread.run_sync(...): timeout
- anyio.Path(...).exists(): timeout
- custom ThreadPoolExecutor(...) cases: success
Outside the sandbox, the exact same command completed successfully and all probe cases
passed.
Minimal repro
This hangs inside the sandbox:
import asyncio
import threading
def cb(loop):
print("thread:call_soon_threadsafe", flush=True)
loop.call_soon_threadsafe(lambda: (print("loop:callback", flush=True), loop.stop()))
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
threading.Timer(0.5, cb, args=(loop,)).start()
loop.run_forever()
print("done", flush=True)
loop.close()
Expected output:
thread:call_soon_threadsafe
loop:callback
done
Actual behavior inside the sandbox:
- only thread:call_soon_threadsafe prints
- the event loop never wakes up
- the process hangs until killed / times out
Root cause evidence
With PYTHONASYNCIODEBUG=1, asyncio logs the real failure:
DEBUG:asyncio:Fail to write a null byte into the self-pipe socket
Traceback (most recent call last):
File "/usr/lib/python3.13/asyncio/selector_events.py", line 152, in _write_to_self
csock.send(b'\0')
PermissionError: [Errno 1] Operation not permitted
This appears to break the Unix selector event loop wakeup mechanism used by
call_soon_threadsafe().
Relevant stdlib path:
- asyncio/selector_events.py, _write_to_self() uses csock.send(b'\0')
- asyncio/base_events.py, shutdown_default_executor() depends on call_soon_threadsafe(...)
That explains why some asyncio.to_thread(...) work appears to finish but asyncio.run(...)
still hangs during shutdown of the default executor.
Extra confirmation
I also verified that this is not specific to the repo or virtualenv startup hooks:
- reproduces with plain python3
- reproduces with python3 -S
- does not require importing any project code
- disappears when rerun outside the Codex sandbox
I also tested lower-level primitives:
- cross-thread socket.socketpair().send(...) fails with PermissionError: [Errno 1] Operation
not permitted - cross-thread os.pipe() write works
So this looks specifically related to the sandbox blocking the socketpair-based wakeup path
used by asyncio on Unix.
What is the expected behavior?
Expected behavior
Codex sandboxed Python processes should be able to use standard-library asyncio thread
wakeups correctly, or the sandbox should detect and clearly report that this runtime pattern
is unsupported.
Actual behavior
The sandbox causes false async failures that look like application bugs:
- hangs in asyncio.to_thread(...)
- hangs in anyio.to_thread.run_sync(...)
- hangs during shutdown_default_executor()
- misleading timeouts in pytest and repo diagnostics
Additional information
No response
Activity
vshikhar95 commentedon Apr 4, 2026
Confirming this issue also explains a pytest symptom I reproduced locally.
In my repo, Codex could run backend pytest directly in the foreground inside the sandbox, but the same sandbox still caused pytest hangs in other execution paths. Outside the sandbox, the same pytest runs completed normally.
So this looks consistent with the underlying asyncio cross-thread wakeup bug described here, with pytest hangs as one practical manifestation.
ned2 commentedon Aug 30, 2026
I can reproduce this on a current Codex/Python stack:
workspace-writesandboxEnd-to-end reproduction
This probe uses only the Python standard library. Textual, pytest, and the application are not required.
Create the standard-library-only probe:
First, run it directly as the host control:
Expected output:
Exit code: 0.
Next, launch the identical command through a Codex
workspace-writesandbox with network access disabled:Codex report reports:
sandbox: workspace-write [workdir, /tmp, $TMPDIR]The command then produces:
Exit code: 124.
worker completedproves that the executor task ran. The missingclosedoutput and exit code124show thatasyncio.run()did not complete its default-executor shutdown before the ten-second outer timeout.For comparison, repeating the codex exec command with:
produces:
and exits
0.This isolates the failure to the Codex Linux sandbox policy used when network access is disabled, rather than Python, the virtual environment, or the application under test.
Lower-level confirmation
Inside the affected sandbox, an
AF_UNIXsocketpair write fails directly:Inside the sandbox,
send()raises:PermissionError: [Errno 1] Operation not permittedThis is the mechanism asyncio uses to wake its Unix selector after
call_soon_threadsafe()is invoked from another thread.I also tested the minimal
asyncio.to_thread()probe with several installed Python versions inside the same affected sandbox:Scheduling an otherwise unnecessary event-loop timer also allows shutdown to complete. That is consistent with the completion callback already being queued but the selector not being awakened by the cross-thread socketpair write.
Real-world impact
I encountered this through a Textual pytest suite. Textual's Markdown renderer submits
MarkdownIt.parseto asyncio's default executor.The affected test printed
PASSED, but teardown then remained in:Python waited for its 300-second executor shutdown timeout. The complete suite finished in approximately 21 seconds outside the affected sandbox but incurred repeated five-minute pauses inside it. Textual only exposed the behavior; it is not needed to reproduce it.
This appears to be the same underlying
seccomp/sendto()problem investigated in #24933 rather than an application, Textual, pytest, or CPython defect.