Skip to content

refactor(codex): run sandboxed Codex without the task image's Python - #5148

Closed
yaoyu-33 wants to merge 3 commits into
NVIDIA-NeMo:fix/host-built-hermes-stirrup-runtimefrom
yaoyu-33:refactor/codex-bash-runner
Closed

yaoyu-33 wants to merge 3 commits into
NVIDIA-NeMo:fix/host-built-hermes-stirrup-runtimefrom
yaoyu-33:refactor/codex-bash-runner

Conversation

@yaoyu-33

@yaoyu-33 yaoyu-33 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #5137, which is stacked on #5094. The base branch fix/host-built-hermes-stirrup-runtime is a copy of #5137's head, so the diff shows only the Codex change. Merge order: #5094, #5137, then this PR; each is retargeted to main after the one below it lands. The Codex change does not depend on #5137's code. Each PR's head lives on the fork; the base branches are copies of the head below it in this repo, kept in sync on every push. GitHub's stack view is not available, because it does not accept pull requests from forks.

What

Codex was the last CLI harness whose sandbox worker ran on the task image's python3. This moves it onto the shared bash runner, so no sandboxed CLI harness needs Python in the task image any more.

  • Codex now starts through harness_runner.sh, like Claude Code, OpenCode, Kilo, OpenClaw and Pi. The runner supplies the prompt on stdin, stamps stdout as events, keeps stderr and writes runtime.json.
  • The sandbox-local HTTP 429 retry proxy moves from Python to sandbox_launcher.mjs, which runs on the Node 22.19.0 that the Codex runtime already installs. It starts the forwarder on a loopback port, then starts Codex with -c model_providers.gym.base_url=<forwarder>.
  • The native-session snapshot (native_session.jsonl) moves to the same launcher (--snapshot).
  • The bootstrap no longer installs python3, and the workdir overlap check is POSIX sh. The installer drops its Python version assertion and its ctypes libstdc++ probe, replaced by the musl path check Pi already uses.
  • stdlib_runner, check_stdlib_runner, the bin/gym-runner interpreter link and RUNNER_FILE are removed. Codex was their only user, and refactor(agent_utils): run sandboxed harnesses with only bash in the task image #5094's harness docs said they would go once Codex no longer needed the task image's Python.
Piece Before After
Codex worker sandbox_runner.py on the task image's python3 (≥ 3.8), run as bin/gym-runner shared harness_runner.sh
429 retry proxy sandbox_transport.py (stdlib http.server + urllib) sandbox_launcher.mjs on the runtime's Node
Native-session snapshot python3 sandbox_runner --snapshot node sandbox_launcher.mjs --snapshot
Bootstrap installs missing python3 and bash; overlap check with python3 -c installs a missing bash; POSIX sh overlap check
Installer asserts Python ≥ 3.8; ctypes libstdc++ probe on musl no Python; libstdc++.so.6 path check on musl

Why

@hemildesai asked to move the remaining harnesses off the task image's Python as a follow-up to #5094. Codex was the only CLI harness left. The Python harnesses are covered separately:

No separate issue: this follows the review discussion on #5094.

Behaviour kept from the Python worker

The launcher keeps the Python worker's behaviour in all of these:

  • Retries. A 429 is retried twice. A numeric Retry-After is honoured, clamped to [0, 30] s. A non-numeric or non-finite value backs off 1 s, then 2 s.
  • Attempt records. Every upstream attempt is written to model_attempts.jsonl:
    • the status;
    • status: null plus the error when the connection fails; the forwarder then answers 502;
    • transport_error when the upstream body is cut short or times out.
  • Header rewrite. x-session-id is replaced with the invocation ID.
  • Environment. Codex gets the same allowlist (PATH, LANG, LC_ALL, HOME, XDG_*, NEMO_GYM_SUPERVISOR) plus the adapter's variables. The runner drops a task NODE_OPTIONS before the launcher starts, the way python3 -I ignored PYTHON* variables.
  • Stops. TERM is passed on to Codex, so a stopped Codex can still flush its last events.
  • Exit status. The launcher exits with Codex's status as a shell would: 128+N when signal N killed it, 127 when Codex cannot be started.

Two differences, both deliberate:

  • One connection per attempt. The forwarder opens a fresh upstream connection per attempt (agent: false), like urlopen did. Node, unlike urllib, ignores http_proxy, which Codex itself never saw either.
  • Line splitting in the snapshot. The snapshot splits lines only at \n, \r\n and \r. Python's splitlines() also split at U+2028 and similar characters, which JSON may contain unescaped inside a string, and so could break a native-session record in two.

Compatibility

  • Task images for Codex need bash and no longer need Python. Images without bash get it from apt-get or apk when running as root, as before.
  • SandboxCommand(stdlib_runner=...) and supervised_launch_command(stdlib_runner=...) are removed. nemo_gym.agent_utils.sandbox_session.RUNNER_FILE and supervisor_client.RUNNER_INTERPRETER are removed too. The migration list in add-or-update-a-harness.mdx says so.
  • HarnessProcessInfo.python (Codex) is removed; runtime.json now comes from the runner and carries hostname and pid.
  • No benchmark-result impact expected: Codex's model calls, retries and outputs are unchanged.

Tests

  • Ported. test_sandbox_runner.py now runs a staged activation through the real supervisor, runner and launcher. It covers:
    • stdin and events;
    • the environment allowlist and the dropped NODE_OPTIONS;
    • services that outlive a natural exit, a timeout or a stop;
    • TERM reaching Codex;
    • the receipt status for exit 7, a TERM death (143) and a missing binary (127);
    • the stop fence.
  • New. test_sandbox_launcher.py tests the forwarder against real HTTP servers:
    • which statuses are retried, and that every attempt is recorded;
    • Retry-After parsing;
    • a refused connection;
    • a cut-short body: timeout, truncated chunked body, truncated Content-Length body;
    • the end-to-end launcher;
    • snapshot path order and line splitting.
  • CI coverage. CI's test container has no Node, which would make all of these skip. So codex_agent/tests/conftest.py installs Node at collection on Linux through a new setup_codex.ensure_node(), which reuses the existing local-mode Node installer, and the install directory is gitignored.
  • Shared tests. The pkill test in test_sandbox_supervisor_client.py now checks the bash runner instead of the interpreter link. The stdlib_runner cases are removed from the bootstrap tests.

Validation

  • macOS (bash 3.2/5.2, Node 25): pytest responses_api_agents/codex_agent/tests tests/unit_tests/test_sandbox_supervisor_{bootstrap,client}.py tests/unit_tests/test_sandbox_session.py tests/unit_tests/test_harness_runner.py: 417 passed, 48 skipped (Linux-only), 1 failed: test_opensandbox_sdk_is_available_in_agent_environment, because opensandbox is missing from the local venv.
  • Linux workstation (bash 5.0.17, about 1,100 visible processes, Node 22.15 installed by the new conftest), at the merge with refactor(agent_utils): run sandboxed harnesses with only bash in the task image #5094's head 05bac0530: the same suites plus test_process_supervisor.py: 508 passed, 6 skipped. Before that merge, refactor(agent_utils): run sandboxed harnesses with only bash in the task image #5094's forking_tool supervisor test failed on this host, with or without this change; 05bac0530 makes forced-stop scans cheaper and fixes it.
  • pre-commit run --files <changed files>: passed.

Smoke run with the real Codex CLI: the full adapter flow on a workstation, driven through the agent's HTTP routes (seed, activation, close), with each task sandbox a Docker container. Codex 0.144.4 was installed into the container by the real installer, and the model was a scripted Responses server on the host that answers 429 once, then a completed message. Results:

Image Python in image Result
debian:bookworm-slim (glibc, bash present) none, before and after completed, output "Done.", attempts [429, 200], receipt confirmed with return code 0, native transcript collected
alpine:3.20 (musl, no bash) none, before and after the POSIX sh bootstrap installed bash and the installer added its missing packages with apk; same result as Debian

Rollout evidence with a real model: pending. This stays a draft until a Codex rollout with a served model runs through the launcher, together with #5094's rollouts.

🤖 Generated with Claude Code

Codex was the last CLI harness whose sandbox worker ran on the task
image's python3, only because its HTTP 429 retry proxy was Python.
Run Codex through the shared harness_runner.sh, behind a small Node
launcher (sandbox_launcher.mjs) on the Node that the Codex runtime
already installs. The launcher keeps the proxy's behaviour (two 429
retries honouring Retry-After up to 30 s, attempt records, transport
errors), the environment allowlist and TERM forwarding, and exits with
Codex's status as a shell would. The native-session snapshot moves to
the same launcher.

The bootstrap, workdir overlap check and installer no longer need
python3. With no remaining user, stdlib_runner and the bin/gym-runner
interpreter link are removed, as the harness docs promised.

Codex tests that need Node install it at collection on Linux, through
setup_codex.ensure_node(), so CI keeps running them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 27, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 0b80097

@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:agent Agent harnesses and Responses API agent behavior feature New capabilities, enhancements, or enablement work labels Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 7cd0f96

…om:NVIDIA-NeMo/Gym into refactor/codex-bash-runner

Signed-off-by: yaoyu-33 <[email protected]>

# Conflicts:
#	fern/versions/latest/pages/agent-server/add-or-update-a-harness.mdx
@yaoyu-33
yaoyu-33 changed the base branch from main to yaoyu-33/host-built-hermes-stirrup-runtime October 27, 2026 20:33
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 44288ba

@yaoyu-33

Copy link
Copy Markdown
Contributor Author

Superseded by #5153, the same commits reopened from a branch in this repo so #5151, #5152 and #5153 can form a GitHub Stack (pull requests from forks cannot join one). This PR keeps the earlier review history; please continue on #5153.

This branch was previously deployed

1 inactive deployment
public — 44288ba2 Deployed Oct 27, 2026 by copy-pr-bot[bot] via release / finalize / notify #7696
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent harnesses and Responses API agent behavior feature New capabilities, enhancements, or enablement work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants