--full-auto and --sandbox workspace-write flags cause indefinite hang with orphaned child processes
What version of Codex is running?
codex-cli 0.66.0
What subscription do you have?
PRO
Which model were you using?
gpt-5.1-codex-max
What platform is your computer?
Linux 6.8.0-87-generic x86_64
What issue are you seeing?
When using --full-auto or --sandbox workspace-write flags with codex exec, commands hang indefinitely even for simple operations that complete in milliseconds without these flags.
Test results:
| Command | Result | Time |
|---------|--------|------|
| codex exec "echo test" | ✅ Works | ~2s |
| codex exec --json "echo test" | ✅ Works | ~2s |
| codex exec --full-auto "echo test" | ❌ HANGS | >2min |
| codex exec --sandbox workspace-write "echo test" | ❌ HANGS | >2min |
Symptoms:
- Command output shows successful completion in JSONL log
- Codex never returns control to caller
- Child processes remain orphaned in
S(sleeping) state exit_code: null, status: "in_progress"persists indefinitely
Note: This is separate from issue #7846 (process substitution). This bug occurs with the --full-auto/--sandbox flags themselves, even with simple commands like echo.
What steps can reproduce the bug?
Minimal reproduction:
```bash
# Step 1: This WORKS (no sandbox flags)
timeout 30s codex exec --dangerously-bypass-approvals-and-sandbox \
"Run: echo 'hello world'"
# Result: Completes in ~2-5 seconds
# Step 2: This HANGS (with --full-auto)
timeout 30s codex exec --dangerously-bypass-approvals-and-sandbox \
--full-auto "Run: echo 'hello world'"
# Result: Times out after 30s
# Step 3: This also HANGS (with --sandbox workspace-write)
timeout 30s codex exec --dangerously-bypass-approvals-and-sandbox \
--sandbox workspace-write "Run: echo 'hello world'"
# Result: Times out after 30s
# Step 4: Check for orphaned processes after timeout
pgrep -af 'codex|echo' | grep -v pgrep
```
### Full reproduction script:
```bash
#!/usr/bin/env bash
set -euo pipefail
echo "=== Test 1: Without --full-auto ==="
time timeout 20s codex exec --dangerously-bypass-approvals-and-sandbox \
"Run: echo test" 2>&1 | tail -3
echo "=== Test 2: With --full-auto (will hang) ==="
time timeout 20s codex exec --dangerously-bypass-approvals-and-sandbox \
--full-auto "Run: echo test" 2>&1 | tail -3
echo "Exit code: $?"
```
What is the expected behavior?
- Commands with
--full-autoshould complete in similar time as without the flag (~2-5s for simple commands) - All child processes should be terminated when Codex exits
- No orphaned processes should remain after command completion
exit_codeshould be set to actual return value (0 for success)
Additional information
Root cause analysis:
The issue appears to be in process group management when sandbox mode is active:
- Missing
setpgid(0, 0)- Child processes not placed in own process group - Signal propagation - Signals sent only to direct child PID, not entire group
- Grandchild orphaning - Sandbox intermediate processes create orphans
- Pipe deadlock - Codex waits for EOF on pipes kept open by orphans
### Related issues:
- #7846 - Process substitution hang (different trigger, same root cause)
- #4726 - Missing child.wait() (closed)
- #3836 - Async process management
### Workaround:
Remove --full-auto flag. Use --json alone if JSON output needed.
5 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Hey @ghul0, thanks for reporting. Like #7846, I wasn't able to repro with Ubuntu 22,
bash, and Codex v0.66.In fact, I don't believe
codex exec --dangerously-bypass-approvals-and-sandbox --full-auto "Run: echo 'hello world'"even runs; Codex errors if you try to run with both--dangerously-bypass-approvals-and-sandboxand--full-auto. Let me know if you're seeing otherwise.Would you mind sharing the
thread-idof a session where you see this issue? You can get thethread-idvia the/feedbackcommand in the CLI. Thanks.Isolated a minimal, single-function test that reliably reproduces this issue. The root cause appears to be asyncio.to_thread()
failing to complete in the exec --full-auto sandbox environment.
---
## Minimal Test Case
### Reproduction Steps
codex exec --full-auto "Run: python -m pytest /tmp/test_asyncio_hang.py -v"
Result: Hangs indefinitely, killed by timeout after 2min (set by codex on bash tool execution) (exit code 124)
codex exec "Run: python -m pytest /tmp/test_asyncio_hang.py -v"
Result: Completes in ~2s
codex --full-auto
Then type: Run: python -m pytest /tmp/test_asyncio_hang.py -v
Result: Completes in ~2s
---
Test Matrix
| Mode | --full-auto | Result | Time |
|---------------------|-------------|--------|-----------------|
| codex exec | ✓ | HANGS | >2min (timeout) |
| codex exec | ✗ | OK | ~2s |
| codex (interactive) | ✓ | OK | ~2s |
| codex (interactive) | ✗ | OK | ~2s |
---
Analysis
The issue is specific to the combination of exec subcommand + --full-auto flag.
asyncio.to_thread() internally uses concurrent.futures.ThreadPoolExecutor to spawn worker threads. In the exec --full-auto sandbox
environment, these threads appear to never complete — consistent with the process group and signal propagation issues described in
this thread.
Notably, the same --full-auto flag works correctly in interactive mode, suggesting the bug lies in how exec mode sets up or tears
down the sandbox process environment.
---
Environment
@ghul0, are you still able to repro this problem? If so, please use the
/feedbackslash command to upload your logs and post the thread ID here.```
markdown
workspace-writeYes, this is still reproducible. It also occurs in the current managed
sandbox used by an interactive Codex agent session—not onlycodex exec --full-auto`.with
Minimal reproduction:
Inside the Codex sandbox:
The worker thread runs and prints its output, but Python never exits.
timeouteventually kills it.
The identical command run outside the sandbox completes immediately with exit
code 0:
Environment:
@openai/codexpackage: 0.129.0bwrapinvokingcodex-linux-sandboxworkspace-write, with network restrictedThis standard-library-only reproduction suggests the problem is in the
sandbox's handling of
asyncio.to_thread()or thread-pool shutdown.It also suggests that the issue persists and now affects an interactive
managed sandbox, rather than only the
codex exec --full-autocase originallyreported.
Feedback/thread ID:
019fd77c-5c0c-7432-a147-cdc677d89098````