Repository navigation
Conversation
The supervisor uploaded into task sandboxes now needs only bash, /proc, sleep and mv, so sandboxed harnesses no longer require Python 3.8+ in the task image. It keeps the CLI and receipt contract: run the harness in its own process group, stop it at the deadline or when the stop file appears (TERM, then KILL the group), and confirm no group member runs. Stops now reach the supervisor through stop.request instead of SIGTERM, so the launch shell no longer ignores TERM and the harness keeps the default disposition. Shared receipt types and timeouts move to supervisor_client; SandboxCommand drops its python field. shell_assignments() renders runner inputs as bash source. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Hemil Desai <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
harness_runner.sh replaces per-harness Python runners: it sources the PARAMS written by shell_assignments(), records runtime.json, applies the harness environment and runs the CLI with file-backed stdio. With events set, it stamps each JSON stdout line with the time it was seen, reading a file so a detached tool holding stdout cannot stall it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Hemil Desai <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
…rmes tests Point the harness guide, package docs and SandboxSession docstring at process_supervisor.sh and harness_runner.sh, drop the Python-in-sandbox requirement and the subreaper drain the bash supervisor no longer performs. Hermes tests use the bash supervisor. The runner stamps a final unterminated event line with the same fallback time as the others on bash < 5. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Hemil Desai <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Hemil Desai <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
Kilo sessions now run through the shared bash harness runner with PARAMS written by shell_assignments(); sandbox_runner.py is gone. A short setup string removes a stale plugin receipt and records the task's HOME/XDG for the task-environment plugin, unset_env drops inherited KILO_*/OPENCODE_*/ OpenAI variables, and the exit code comes from the cleanup receipt. Path checks are POSIX shell, the bootstrap installs only bash, and the installer drops its Python checks. The SQLite snapshot moves host-side: kilo.db and its WAL files are downloaded and backed up locally. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Hemil Desai <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
…ndbox Claude sessions now launch through the shared bash harness_runner.sh with params.sh instead of sandbox_runner.py and input.json. The offline runtime installer is a bash script with the same SHA-256, version and lock semantics, so task images need bash and coreutils but no Python. Signed-off-by: Hemil Desai <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
Launch OpenClaw through the shared bash harness_runner.sh with PARAMS from shell_assignments() and a staged prompt file, replacing sandbox_runner.py. The workdir overlap check is POSIX sh, session setup installs only a missing bash, and the runtime installer drops its Python checks (apk now reports whether musl images have libstdc++; the prepare step already guards the runtime path against the task workdir). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Hemil Desai <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
Task images now need only bash. The shared harness_runner.sh replaces sandbox_runner.py: PARAMS carry the CLI argv, environment and stdio files, and a short setup records the task HOME/XDG directories for the shell.env hook, removes a stale initialization receipt and creates the private CLI directories. The SQLite snapshot moves to the agent server: after confirmed cleanup the adapter downloads opencode.db (and its -wal/-shm files when present) and runs the same export there, producing the same export.json and observations.db. The bootstrap no longer installs python3 and checks workdir overlap with POSIX shell, and the runtime installer serializes with flock, or a reclaimable lock directory without it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Hemil Desai <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
Pi now runs under the shared bash harness runner: the adapter stages params.sh and prompt.txt, and the runner records [seen_at, event] lines. Session setup no longer installs python3, the runtime installer checks for the musl C++ library by path instead of with ctypes, and the host parser skips recorded lines that are not [number, object] records. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Hemil Desai <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
…available A missing or undownloadable session database again leaves no export, so collection reports "OpenCode sandbox runner returned no valid result" with the output log, as when export.json was missing before. The export no longer depends on copying the observation store: a failed copy, like the failed observations.db download before, only adds observation gaps. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Hemil Desai <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Hemil Desai <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
The bash supervisor no longer takes an interpreter, so NOOA drops the removed SandboxCommand.python field (its own pinned Python still runs its worker), and the Codex worker keeps its Python runner under the bash supervisor: its sandbox-local 429 retry proxy still needs Python. OpenCode drops sandbox_python_executable; sandbox_path_prefix now reaches the CLI through the runner setup. Tests and READMEs name process_supervisor.sh. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
… runner names On bash < 4.2 printf has no strftime, so every event was stamped with an empty time and the host parsers dropped them all; fall back to date. Strip a trailing CR before recording a JSON line. Inherited variables named like runner PARAMS (setup, events, stdout, ...) no longer configure the runner or leak into the CLI. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
…he bash supervisor A stopped CLI's tools that run in their own session (OpenCode and Codex start every shell tool that way) kept writing to the task after a confirmed receipt. Before stopping the harness, the supervisor now records its descendants outside its process group from /proc and kills them, and the groups they lead, with the harness; confirmation waits for them too. Services orphaned before the stop are still left for the sandbox owner. The supervisor also: - reads each /proc/PID/stat whole and never evaluates its fields as arithmetic, so a process name holding a newline cannot run code or hide a group member; - refuses to launch without a readable /proc, and counts unreadable process state as running; - bounds the wait for a KILLed harness and writes a negative receipt instead; - exits on a missing option value or separator instead of looping or running part of the command, and ignores an inherited errexit. Launches render fixed-point seconds, and a deadline shorter than the supervisor's centisecond resolution expires before launch instead of leaving no receipt. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
…runner descriptors Without job control bash starts an async command with INT and QUIT ignored, and the CLI's tools inherited that. The CLI also inherited the runner's read and events descriptors, so a tool could write raw lines into events.jsonl. Reset the two signals (bash 5 honours the reset) and close both descriptors for the CLI. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
…e to older bash Without flock, the Claude installer never reclaimed the lock of a killed installer, and OpenCode's reclaim could delete a lock another installer had just taken (or skip an owner killed before it wrote its PID). Both now take a symlink that names the owner by PID and start time, and remove a dead owner's lock only under a second lock after re-reading it. The Claude installer lowercases the trusted digest without bash 4 expansions. The Pi installer no longer fails under set -u on bash < 4.4 when it needs no packages, and checks every default musl library directory for libstdc++. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
sqlite3's context manager commits but does not close, so a failed export kept the copied databases open while the snapshot directory was removed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
…wn sessions The receipt docstring, the harness guide and the Codex, Pi, OpenCode, OpenClaw, Hermes and Terminal-Bench READMEs now describe what the bash supervisor does: it kills the harness group and, after a forced stop, the descendants that ran in other process groups when the stop began; processes that left the harness earlier stay with the sandbox owner. The receipt documents shell exit statuses. The Kilo and local-provider tests cover a tool in its own session again. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
… stop test shell_assignments() now raises for NUL and non-string words, which bash would silently drop or which raised an opaque TypeError. The Hermes close test stops the supervisor through the stop file alone, as production does, and the sandboxed Hermes README states that the supervisor needs the task image's bash. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test 01ac0f1 |
…completed tools The bash port's tests asserted that a tool still running in its own session survives a close, and modelled a completed tool's service as a direct child of the CLI. With the supervisor's stop-time cleanup, an in-flight detached tool is stopped again, as before the port; a service left by a tool that already exited still survives. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test fb642f9 |
…hosts A forced stop scans every process in /proc several times, and each /proc/PID/stat parse used a longest-prefix match (quadratic in bash) and three regex compilations. On a host with about 1,100 processes a stop took 1.65 s, so Hermes's close test, which allows 2 s and polls for the receipt once a second, failed there while CI passed. Parse with a shortest-prefix loop and glob digit checks, let the forced drain take liveness from its scan instead of a second /proc pass, and skip the extra scan once the harness has exited (the drain scans next). A stop on the same host now takes about 0.55 s. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test 05bac05 |
…DIA-NeMo#5137 Signed-off-by: yaoyu-33 <[email protected]>
|
/ok to test b1c63b8 |
| leader=${group[pid]} | ||
| if [[ -n ${kept[pid]} || $pid == "$$" ]]; then | ||
| continue | ||
| elif [[ -n ${tracked[pid]} && ${tracked[pid]} == "${start[pid]}" ]]; then |
There was a problem hiding this comment.
No test fails when the start-time comparison on this branch is removed. test_reused_ids_are_neither_awaited_nor_killed covers reached_alive and kill_reached, but scan records the new start time at line 130, so a process that reused a tracked PID is pulled in and then killed before the guard in kill_reached can help. It needs the PID to wrap during a stop, so it is unlikely. A test that sets tracked[pid] to a stale start time and runs scan would pin it.
|
|
||
| # Succeeds when process $1, started at $2, inherited this supervisor's marker. A process that started | ||
| # before the supervisor cannot have, so its environment is not read. | ||
| marked() { |
There was a problem hiding this comment.
marked reads the environment of every process that started after the supervisor and is not yet reached, on each scan. On bash 5.2 a scan took about 0.2 s with 900 processes visible, 0.7 s with 1,700 and 3 s with 3,700, mostly in these reads. That is fine inside a pod's own PID namespace. Does any provider run a sandbox in the host's PID namespace? There the poll interval and the receipt would stretch.
| grace=$((NOW + cleanup)) | ||
| while kill -0 "$harness" 2>/dev/null && ((NOW < grace)); do | ||
| sleep 0.05 | ||
| scan |
There was a problem hiding this comment.
Removing this rescan passes every test. The rescans after the loop cover most of it, so only a process that leaves the harness during the grace period and drops the marker would differ. A test for that case would show whether the per-round rescan is needed.
| # unset_env array of extglob patterns naming inherited variables to drop | ||
| # events file receiving each JSON object line of stdout as [seen_at, object] | ||
| # Writes runtime.json beside PARAMS. Exits with the command's status, 125 when the runner fails before | ||
| # starting it (including an exit from setup), or 126 or 127 when the command could not be started. |
There was a problem hiding this comment.
Only Kilo tells these statuses apart from the CLI's own. Claude Code (claude_code_agent/app.py:793), OpenCode (opencode_agent/app.py:1275), OpenClaw and Pi still report 125, 126 and 127 as the CLI's exit code. Is that intended for this PR?
| "XDG_CACHE_HOME", | ||
| "XDG_STATE_HOME", | ||
| # Lets the supervisor find Codex's tools after they leave its process tree. | ||
| "NEMO_GYM_SUPERVISOR", |
There was a problem hiding this comment.
Codex passes the marker explicitly because it builds its tools' environment from an allowlist. For the other CLIs the marker reaches tools only if the CLI hands them the parent's environment, and nothing shows that. A smoke rollout in which the model runs env | grep NEMO_GYM_SUPERVISOR would settle it for each harness.
| f"{quote(self.config.runtime_python)} -I {quote(remote + '/process_supervisor.py')} " | ||
| f"--timeout {self.config.sandbox_timeout} --receipt {quote(remote + '/cleanup.json')} -- " | ||
| f"bash {quote(f'{remote}/{SUPERVISOR_FILE}')} " | ||
| f"--timeout {self.config.sandbox_timeout} --cleanup-timeout {DEFAULT_CLEANUP_TIMEOUT} " |
There was a problem hiding this comment.
--timeout is still the raw float string. The supervisor accepts fixed-point values of at least 0.01, so a smaller value or exponent form such as 1e+16 exits 2 with no receipt. supervisor_client._seconds already formats it.
What
Sandboxed harnesses no longer need Python in the task image. The shared process supervisor (
nemo_gym/agent_utils/process_supervisor.sh) and a shared harness runner (harness_runner.sh) are bash scripts, and the OpenCode/Kilo SQLite snapshot moves to the agent server. Claude Code, OpenCode, Kilo, OpenClaw and Pi run their CLIs through the bash runner; Hermes, NOOA and Stirrup keep their own Python workers under the bash supervisor.This ports Hemil Desai's bash sandbox runtime change (his commits are kept with authorship) onto
main, adapts it to code that only exists here, and adds fixes found in review.Before / after
Colour key: amber = Python inside the task sandbox, green = moved from Python to bash, blue = moved out of the sandbox to the agent server, grey = Python worker kept as is.
Before: every sandboxed harness needs Python ≥ 3.8 in the task image.
flowchart LR subgraph host["Agent server"] S["SandboxSession<br/>supervisor_client"] end subgraph box["Task sandbox (task image)"] B["Bootstrap<br/>apt/apk python3 if missing<br/>workdir check with python3 -c"]:::py I["Runtime installers<br/>install_claude_runtime.py<br/>Python ≥ 3.8 assert, fcntl lock,<br/>hashlib digest, ctypes libstdc++"]:::py SUP["process_supervisor.py<br/>subreaper drain"]:::py R["sandbox_runner.py<br/>one per harness"]:::py CLI["Harness CLI<br/>Claude Code · OpenCode · Kilo · OpenClaw · Pi"] W["Codex worker + 429 proxy<br/>Hermes · NOOA · Stirrup workers"]:::keep DB[("opencode.db / kilo.db")] X["SQLite export<br/>sandbox_runner.py --snapshot"]:::py end S -->|"seed"| B --> I S -->|"launch: python3 -I"| SUP --> R --> CLI SUP --> W CLI --> DB --> X -->|"export.json<br/>observations.db"| S classDef py fill:#fde68a,stroke:#b45309,color:#111 classDef keep fill:#e5e7eb,stroke:#6b7280,color:#111After: the shared pieces need only bash; Codex, Hermes, NOOA and Stirrup still bring or use their own Python worker.
flowchart LR subgraph host["Agent server"] S["SandboxSession<br/>supervisor_client<br/>shell_assignments() → params.sh"] X["SQLite export<br/>snapshot.py"]:::host end subgraph box["Task sandbox (task image needs bash)"] B["Bootstrap<br/>apt/apk bash only if missing<br/>POSIX sh workdir check"]:::sh I["Runtime installers<br/>install_claude_runtime.sh<br/>flock or owner-symlink lock,<br/>sha256sum, path / apk checks"]:::sh SUP["process_supervisor.sh<br/>/proc rescans + env marker"]:::sh R["harness_runner.sh<br/>shared by 5 harnesses"]:::sh CLI["Harness CLI<br/>Claude Code · OpenCode · Kilo · OpenClaw · Pi"] W["Codex worker + 429 proxy<br/>Hermes · NOOA · Stirrup workers"]:::keep DB[("opencode.db / kilo.db<br/>+ WAL files")] end S -->|"seed"| B --> I S -->|"launch: bash"| SUP --> R --> CLI SUP --> W CLI --> DB -->|"download raw files"| X classDef sh fill:#bbf7d0,stroke:#15803d,color:#111 classDef host fill:#bfdbfe,stroke:#1d4ed8,color:#111 classDef keep fill:#e5e7eb,stroke:#6b7280,color:#111process_supervisor.pyprocess_supervisor.shsandbox_runner.pyper harnessharness_runner.shinstall_claude_runtime.pyinstall_claude_runtime.shfcntl,hashlib)flockor owner symlink,sha256sumctypesprobeapk infocheckspython3 -csh--snapshot)snapshot.py)sandbox_runner.py+sandbox_transport.pyKnown exceptions (follow-ups, not in this PR)
These still put Python or the network into the task sandbox. No tracking issues are filed yet.
python3≥ 3.8 in the task image and apt/apk-installs it when missing. Python runs its workdir overlap check, the installer's version and libstdc++ probes, its worker, the 429 retry proxy (sandbox_transport.py) and the--snapshotexport. Only the proxy has no bash equivalent; where it should live (for example the agent server'srate_limit_proxy) is still to be decided. Once Codex moves,stdlib_runner,RUNNER_INTERPRETERandbin/gym-runnercan go.uvand runsuv venv --python 3.13anduv pip installinside the sandbox, from the network, withcwdset to the task workdir, without--no-config, and withoutUV_CACHE_DIRorUV_PYTHON_INSTALL_DIR: a task'suv.tomlor[tool.uv]can change the install, uv's cache and managed Python land in the task's home, and--python 3.13can bind the image's own python3.13.uv pip install stirrup==...; it setsUV_CACHE_DIRandUV_PYTHON_INSTALL_DIRbut not--no-config.hermes_sandboxed_agent/prepare_runtime.shand NOOA do. The harness guide now presents these three paths as exceptions, not options.Why
Before this change the supervisor and per-harness runners ran on whatever
python3the task image had:python3older than 3.8 failed the task (seen on SWE images with old Python);python3was apt/apk-installed into the task image, changing what both the agent and the verifier see (for example Go/Rust/JS images in multilingual SWE sets).No public issue; this mirrors internal work on the same change.
Port notes (differences from the original change)
mainthe Codex worker runs a sandbox-local 429 retry proxy (sandbox_transport.py) that has no bash equivalent, so Codex still needs Python ≥ 3.8 in the task image. Where that proxy should live is an open question for a follow-up.main; those parts are left out.sandbox_python_executable;sandbox_path_prefixnow reaches the CLI through the runner setup.benchmarks/swe_together/opencode.yamlis updated.SandboxCommand.pythonfield; its pinned Python still runs its worker.Fixes on top of the port
/procwhen the stop begins and on every polling round. It kills the harness group plus everything it reaches: descendants of the harness, of its group and of reached processes, and processes that inherited the harness'sNEMO_GYM_SUPERVISORenvironment marker (for example a tool that daemonizes, or a TERM handler that runssetsid ... &and exits). Marked processes that had already left the harness when the stop began are preserved as services, as the subreaper did onmain. What is not reached is documented: a process that leaves between two scans after dropping the marker. The Codex runner passes the marker through its env allowlist./proc/PID/statwhole and never evaluates its fields as arithmetic (a crafted process name could run code and hide a member); refuses to launch without a readable/proc; bounds the wait for a KILLed harness; rejects malformed arguments instead of looping; ignores an inherited errexit. Launches render fixed-point seconds, and a deadline under one centisecond expires before launch instead of leaving no receipt./proc/PID/statseveral times, and on a busy host this made stops slow (1.65 s with about 1,100 processes, so Hermes's close test, which allows 2 s, failed there while CI passed). Parsing no longer uses bash's quadratic longest-prefix match or a regex per field, the drain takes liveness from its scan instead of a second pass, and no extra scan runs once the harness has exited. The same stop now takes about 0.55 s.${1%$'\r'}took seconds per MB); an inheritedset -eno longer stops the runner at a non-JSON line; a failedexecredirection no longer falls through into events mode. The runner exits 125 for its own failures (badcwd, anexitin setup) and 126/127 when the CLI could not be started, and Kilo reports these apart from Kilo's own exit status. A cancelled Kilo run reports no exit code, as before.set -uon bash < 4.4 and checks all musl library directories; the OpenCode installer removes a partly staged binary on any failure and no longer reuses a cached binary whose--versionfails.shell_assignments()rejects NUL and non-string words.Compatibility
nemo_gym.agent_utils.process_supervisor(Python) is removed;CleanupReceipt,exec_timeoutand the constants live innemo_gym.agent_utils.supervisor_client.SandboxCommand(python=...)andsupervised_launch_command(python=...)are removed. Out-of-tree adapters need the migration infern/versions/latest/pages/agent-server/add-or-update-a-harness.mdx.return_codeis now the shell status (128+N for a signal death) instead of −N; a missing CLI gives a confirmed receipt with 126/127, and a runner failure before the CLI starts gives 125. The harness guide's migration note lists these together with the removedpython=parameters and the bash requirement.NEMO_GYM_SUPERVISORenvironment variable.Validation
Local (macOS, bash 3.2 and 5.2; Linux-only
/proctests are skipped here and run in CI):pytest tests/unit_tests responses_api_agents/{opencode,kilocode,codex,pi,openclaw,claude_code,hermes_sandboxed}_agent/tests: 13766 passed, 480 skipped, 50 failed, 1 collection error. All 50 failures also fail on unmodifiedmainin the same local venv (missingopensandbox/mlflow, macOS-specific telemetry/CI checks; one flaky Harbor test); the collection error istest_exporters.pyneedingmlflow.pre-commit run --files <changed files>: passed.Review round 2 (local, macOS):
tests/unit_tests/test_{harness_runner,process_supervisor,sandbox_supervisor_client,sandbox_supervisor_bootstrap,sandbox_session}.py,responses_api_agents/{kilocode,claude_code,opencode,codex,pi,openclaw}_agent/tests): 1910 passed, 228 skipped, 3 failed. The 3 failures aretest_opensandbox_sdk_is_available_in_agent_environment, which needsopensandbox, missing from the local venv./proc: harness, tools, orphaned group member and daemons reached; earlier service and its children preserved; reused group not killed.uname.Linux host (bash 5.0, about 1,100 processes), at 05bac05:
responses_api_agents/hermes_agent/tests: 349 passed.test_close_preserves_interrupted_observations_before_releasefailed in both cases at fb642f9 and passed 5 of 5 runs with the fix.tests/unit_tests/test_{process_supervisor,sandbox_supervisor_client,harness_runner}.py, including the Linux-only supervisor tests: all passed. The new name-parsing test fails on a parser that splits at the first") ".Rollout evidence: pending — this stays a draft until smoke rollouts run on a Debian image, an old-Python SWE image and an Alpine image where bash gets auto-installed.
🤖 Generated with Claude Code