Skip to content

fix(agent): build Hermes and Stirrup runtimes on the host - #5137

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

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

Conversation

@yaoyu-33

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

Copy link
Copy Markdown
Contributor

Stacked on #5094; #5148 (Codex) is stacked on this PR. The base branch refactor/bash-sandbox-runtime is a copy of #5094's head, so the diff shows only this PR's changes. Merge order: #5094, then this PR, then #5148; each is retargeted to main after the one below it lands. 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.

The merge of main here (d4c74ed3a) had one conflict, in Hermes's install. It carries #4567's mcp>=1.28.1,<2 requirement and streamablehttp_client import check into the new runtime.

What and why

ananthsub pointed out on #5094 (Hermes, Stirrup, docs) that Hermes and Stirrup still upload uv into the task sandbox and build a virtual environment there from the network. Hermes ran it with the task workdir as cwd, without --no-config, UV_CACHE_DIR or UV_PYTHON_INSTALL_DIR. That meant three problems:

  • a task's uv.toml or [tool.uv] could change the install;
  • uv's cache and managed Python landed in the task's HOME, where the agent and verifier see them;
  • --python 3.13 could bind the image's own python3.13.

Stirrup had the same problem but set the two env vars; it still lacked --no-config. #5094 lists both as known exceptions. This PR removes them.

nemo_gym/agent_utils/sandbox_python.py (new): SandboxPythonRuntime. On the Agent Server host it:

  • probes the sandbox's architecture, C library and glibc version (probe_sandbox_platform());
  • downloads a pinned python-build-standalone CPython 3.13.14 (20260805, install_only_stripped) for that platform and checks its published SHA-256 on every use. The digests come from the release's SHA256SUMS, whose install_only gnu entries match NOOA's existing pins. musl and aarch64 are included;
  • installs the harness's requirements into a separate site-packages archive with uv pip install --no-config --target … --python-platform <arch>-manylinux_2_<N>|<arch>-unknown-linux-musl --python-version 3.13.14 --only-binary :all:.
    • The manylinux level never exceeds the sandbox's glibc.
    • Only requirements given as direct URLs are built from source (--no-binary hermes-agent for Hermes pinned to a commit). Every other package must publish a wheel for the sandbox's platform.
    • Versions are constraints taken from the agent environment's index-installed packages, so the sandbox runs what the adapter is tested with, as the harness guide's installation contract asks. I first used overrides; the Stirrup smoke caught that an override replaces lxml[html_clean] with plain lxml and drops lxml_html_clean. Adapter-specific overrides are an explicit field: Stirrup passes its overrides.txt (Pillow).
  • caches both archives under ~/.cache/nemo_gym/sandbox_python. Concurrent cold seeds in a process share one build, writes are atomic across processes, and a failed build is retried by the next seed.

nemo_gym/agent_utils/install_python_runtime.sh (new, runs in the sandbox with sh, tar/gzip, mv, rm):

  • unpacks both archives in a private .setup-<uuid> directory under the runtime directory;
  • checks the harness import there with python -I, cwd=/, and HOME inside the runtime directory (importing Hermes writes ~/.hermes);
  • publishes with an atomic rename(2). It loops until a runtime that passes the check is in place, so concurrent seeds share whichever one wins, and a runtime that fails its check (for example one from another platform) is set aside and replaced.

The runtime lives at /tmp/nemo-gym-<harness>-runtime-<key>/python. The key hashes the Python pin, the requirements, the overrides and the agent environment's versions, so a runtime left in the sandbox is reused only when it was built from the same inputs. Seed-time execs run from /, and nothing is written into the task's workdir or HOME.

Adapters.

  • Hermes and Stirrup call RUNTIME.is_installed() / RUNTIME.install() at seed. The activation argv and the runner files are unchanged apart from the interpreter path.
  • uv_bootstrap.py and its tests are removed; nothing else used it.
  • Hermes's uv_cache_dir option is removed.

Docs. The harness guide no longer lists Hermes and Stirrup as exceptions; Codex stays. Its shared-module table and installation-contract example now describe sandbox_python.py, and the paragraph that recommended NOOA now points at SandboxPythonRuntime (NOOA's runtime still installs packages from the network in the sandbox). The Hermes and Stirrup READMEs describe the new requirements.

No issue was filed; this is the follow-up named in #5094's "Known exceptions".

Compatibility

  • Sandbox requirements drop: no network, uv or Python needed for seeding; sh and tar with gzip are. glibc ≥ 2.17 or musl; x86_64 or aarch64. Hermes still needs bash and the Model Server's address, as before.
  • Agent Server requirements rise: it needs uv (it already needed it for the old path) and access to GitHub releases and the package index (or a mirror via UV_* env vars, which --no-config still honors).
  • Dependency versions change: the sandbox's versions now follow the agent venv (constraints) instead of a fresh resolve at seed time.
  • Hermes config: uv_cache_dir is removed. BaseServerConfig ignores unknown keys, so configs that set it still load.
  • Runtime paths change: /tmp/nemo-gym-hermes-runtime-<commit>/venv → /tmp/nemo-gym-hermes-runtime-<key>/python. An image that baked the old venv path no longer short-circuits the install.
  • Cold-seed cost: about 35 MB Python plus 20 MB (Hermes) or 77 MB (Stirrup) of site-packages are uploaded per new sandbox. The host build happens once per host and platform.

Validation

  • pre-commit run --files <changed files>: all hooks pass, no changes.
  • tests/unit_tests/test_sandbox_python.py (new, 26 tests), passing on macOS and Linux:
    • platform probe and manylinux selection;
    • environment pins;
    • directory keying;
    • host uv argv (--no-config, platform, --only-binary, --no-binary only for URL requirements, constraints, adapter overrides, scratch cwd);
    • shared and retried builds;
    • Python build checksum (download and every use);
    • sandbox-side install on the local provider, all with a hostile task (below): a cold install, 4 concurrent installs, a broken runtime replaced while 2 installs race, and an import failure that publishes nothing.
  • Regression test test_seeding_ignores_the_task_uv_configuration_and_leaves_the_task_untouched. The task's workdir has a uv.toml and a pyproject.toml [tool.uv] pointing at a dead index, and its PATH has a uv that records calls and exits 2. Seeding succeeds, the fake uv is never called, and the workdir and HOME are byte-for-byte unchanged while the harness writes under the runtime's own HOME. I checked that the test fails when the HOME redirect in the installer is removed.
  • responses_api_agents/stirrup_agent/tests on Linux: 171 passed.
  • responses_api_agents/hermes_agent/tests on Linux: 346 passed, 2 failed. The 2 failures (test_close_preserves_interrupted_observations_before_release[False|True], "launch outcome is unknown; termination deadline exceeded") also fail on refactor(agent_utils): run sandboxed harnesses with only bash in the task image #5094's head with the base Hermes files on the same host, regardless of TMPDIR. I checked at 7908559f8, and they still fail with fb642f9d2 on this branch. They exercise only the supervisor's close path, which this PR doesn't touch, so they need looking at on refactor(agent_utils): run sandboxed harnesses with only bash in the task image #5094.
  • On macOS, the Hermes suite passes (342 passed, 6 Linux-only skipped). The Stirrup end-to-end tests that need /proc for the bash supervisor fail there; that is unrelated and they pass on Linux.
  • install_python_runtime.sh by hand with --network none, three rounds each:
    • debian:bookworm-slim (no Python), python:3.13-slim (image has Python 3.13.17) and alpine:3.20 (musl, BusyBox, no bash);
    • each round: two concurrent installs over a broken runtime, plus a failing import check.
    • Both installs succeeded every time. The runtime ran its own 3.13.14, the task's uv.toml and HOME were untouched, the setup directory was removed, and a failing check published nothing. On Alpine, pydantic_core and yaml import from musllinux wheels.

Rollout evidence

Real-model smoke rollouts with nvidia/nemotron-3-ultra-550b-a55b (NIM) on an x86_64 Linux workstation, using the Docker sandbox provider:

  • Each sandbox was on a docker network create --internal network: it reached only the Gym Model Server proxy on the gateway, with no route to the internet by IP or by name.
  • The agent owned the sandbox, with workdir: /workspace.
  • Task: "compute 37 * 43 and write only the number to answer.txt in the current working directory", checked by reading /workspace/answer.txt in the sandbox.
  • The host's root disk was full, so each sandbox's /tmp was a per-run bind mount from /dev/shm. docker cp does not write into tmpfs mounts.
Harness Image Seed (host cache) Image python3 / uv / internet After seed: /workspace, ~ Tools /workspace/answer.txt Close
Stirrup debian:bookworm-slim 32.0 s (cold build) none / none / unreachable empty, .bashrc .profile code_exec, code_exec, finish 1591 200, container removed
Hermes debian:bookworm-slim 35.0 s (cold build) none / none / unreachable empty, .bashrc .profile terminal, terminal 1591 200, container removed
Hermes python:3.13-slim 18.1 s (warm) image has /usr/local/bin/python3; runtime still reports 3.13.14 under /tmp/nemo-gym-hermes-runtime-…/python empty, unchanged terminal, terminal 1591 200, container removed

After merging main (Hermes venv now has mcp 1.30.0 and the runtime adds mcp>=1.28.1,<2), I reran the same checks on debian:bookworm-slim. Both passed, with the same sandbox findings and /workspace/answer.txt = 1591, and their containers were removed. Hermes seeded in 17.4 s with a fresh host build (terminal ×2); Stirrup seeded in 32.0 s (code_exec ×2, finish). On Linux after the merge: Stirrup 171 passed; test_sandbox_python.py 26 passed; Hermes 346 passed plus the same 2 pre-existing failures.

An earlier Hermes run (with the overrides version) seeded in 18.5 s from a cold host cache with a 15 MB site-packages archive. The constraints version is 20 MB because it keeps the extras the overrides dropped.

Not in this PR (follow-ups)

  • During activation, Hermes's runner imports run_agent before it sets HERMES_HOME, so ~/.hermes still appears in the task's HOME after an episode (seen in the smoke). Seeding no longer writes it. This is existing runner behavior.
  • Codex's task-image Python stays an exception; where its 429 proxy lives is the maintainers' call.

🤖 Generated with Claude Code

@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.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:agent Agent harnesses and Responses API agent behavior bug Something isn't working labels Oct 27, 2026
yaoyu-33 and others added 2 commits October 27, 2026 13:24
Hermes and Stirrup uploaded uv into the task sandbox and built a virtual
environment there from the network, with the task workdir as cwd and without
--no-config. A task's uv.toml or [tool.uv] could change the install, uv's cache
and managed Python landed in the task's HOME, and --python 3.13 could bind the
image's own interpreter.

Add nemo_gym/agent_utils/sandbox_python.py. On the Agent Server it downloads a
pinned python-build-standalone CPython for the sandbox's architecture and C
library, checks its SHA-256, and installs the harness's requirements into a
site-packages archive with uv --no-config --python-platform --only-binary :all:,
constrained to the agent environment's versions. Only direct-URL requirements,
such as Hermes at a commit, are built from source. Both archives are cached on
the host. install_python_runtime.sh unpacks them under /tmp, checks the harness
import with HOME inside the runtime directory, and publishes the runtime with an
atomic rename, so concurrent seeds share one runtime and a runtime that fails
its check is replaced. The sandbox needs sh and tar, but no network, uv or
Python.

Remove uv_bootstrap.py and Hermes's uv_cache_dir option, update the tests, and
drop Hermes and Stirrup from the harness guide's exceptions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…-stirrup-runtime

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

# Conflicts:
#	responses_api_agents/hermes_agent/sandbox.py
#	responses_api_agents/hermes_agent/tests/test_app.py
…o/Gym into fix/host-built-hermes-stirrup-runtime

Signed-off-by: yaoyu-33 <[email protected]>
yaoyu-33 added a commit to yaoyu-33/Gym that referenced this pull request Oct 27, 2026
@yaoyu-33
yaoyu-33 changed the base branch from main to yaoyu-33/bash-sandbox-runtime October 27, 2026 20:31
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 6b720aa

@github-actions

Copy link
Copy Markdown
Contributor

@yaoyu-33
yaoyu-33 changed the base branch from yaoyu-33/bash-sandbox-runtime to refactor/bash-sandbox-runtime October 27, 2026 20:52
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

Superseded by #5152, 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 #5152.

This branch was previously deployed

1 inactive deployment
public — 6b720aa3 Deployed Oct 27, 2026 by copy-pr-bot[bot] via release / finalize / notify #7697
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 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants