Skip to content

feat(pi): restrict the egress of agent-created sandboxes - #5554

Merged
yaoyu-33 merged 10 commits into
NVIDIA-NeMo:mainfrom
gwarmstrong:georgea/pi-agent-egress
Nov 5, 2026
Merged

yaoyu-33 merged 10 commits into
NVIDIA-NeMo:mainfrom
gwarmstrong:georgea/pi-agent-egress

Conversation

@gwarmstrong

@gwarmstrong gwarmstrong commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

  • A shared helper, restrict_sandbox_network, in nemo_gym/agents/utils/sandbox_network.py. It is exported from nemo_gym.agents together with SandboxNetworkAccess. It turns a network_access setting into the existing restricted_network_policy for a sandbox the agent is about to create:

    • inherit leaves the spec unchanged;
    • model_only allows only the Model Server's host;
    • model_and_tools also allows each MCP grant's host.

    It fails closed for providers other than OpenSandbox, and it rejects a spec that already sets provider_options.network_policy.

  • pi_agent gains network_access (default inherit) for the sandboxes it creates. The policy is fixed when a sandbox is created, so a session that borrows a task sandbox rejects any other value.

  • pi_agent gains sandbox_runtime_dir: an absolute sandbox path that holds a preinstalled runtime in the installer's node/ and pi/ layout. Setup checks that the runtime runs pi_version instead of installing one, so a sandbox without internet can run Pi.

  • README: both settings.

Documentation for harness authors, requested by @yaoyu-33 so new harnesses follow the same rule: the Add or Update a Harness page gets a section on restricting an owned sandbox's egress (the field, the helper call, which hosts each value allows, 422 refusals, getting a runtime into a restricted sandbox, the server-exposure and egress-mode caveats), the shared-module table lists agents/utils/sandbox_network.py, the OpenSandbox page points at restrict_sandbox_network, and the add-harness skill adds the matching checklist item, tests, model_only pairing run and egress exit check.

Second review follow-up: Pi's benchmark profile sets network_access: model_only and requires sandbox_runtime_dir (null keeps an image prebaked at the default path), so a run that uses the profile as shipped no longer gets open internet; search presets override to model_and_tools. restrict_sandbox_network takes the provider instead of its name, so the move to #5363's SandboxSpec.egress_rules only changes its body. The profile tests read each profile's network settings from its own file.

Why. #5222 names pi_agent as the replacement for pi_sandboxed_agent. The deprecated agent's benchmark profile sets network_access: model_only, so its sandboxes can reach only the Model Server, or the Model Server plus the search server for the HLE search presets. pi_agent had no equivalent, so every sandbox it created got the provider's default network. On our OpenSandbox cell, that default reached GitHub, Google, package registries and the HLE dataset's Hugging Face page. Evaluations that allow no internet except a search tool could therefore not move to the session harness.

A sandbox limited to the Model Server also cannot download Pi's runtime, hence sandbox_runtime_dir.

The helper is shared. Follow-up PRs add the same setting to opencode_agent, codex_agent, openclaw_agent, hermes_agent and claude_code_agent. It uses the existing restricted_network_policy, and can map onto #5363's egress_rules once that lands.

Part of #5552.

Validation

  • gym env test +entrypoint=responses_api_agents/pi_agent +should_validate_data=true: 347 passed, 22 skipped, 1 failed. The failure is test_gym_extensions[test_gym_mcp.mjs], which needs Node 22; the local host has Node 19, and the test fails the same way on main.

  • tests/unit_tests/agents/test_sandbox_network.py (new): 6 passed. pytest tests/unit_tests/agents: 272 passed. Three tests in test_outcome_policy.py import cloudpickle, which this environment lacks; they fail the same way on main.

  • tests/unit_tests/test_public_api_facades.py and tests/unit_tests/test_import_linter_coverage.py: 803 passed.

  • With the behavior disabled, the new helper and pi_agent tests fail: model-only and model-and-tools egress, the borrowed-sandbox rejection, the policy conflict, and the preinstalled runtime.

  • Review follow-up (8a32f14): restrict_sandbox_network raises AgentSeedRejectedError, still a ValueError, for an unenforceable network_access (an explicit provider policy as well, a provider without network policies, an unreachable endpoint), so every adapter refuses the seed with a terminal 422 instead of a retried 500. Pi builds tool egress only from the MCP grants it keeps. tests/unit_tests/agents/test_sandbox_network.py: 8 passed. Pi: test_unenforceable_network_access_is_a_terminal_seed_refusal (HTTP 422, provider closed, no sandbox, no session; conflicting policy and Docker) and test_tool_egress_leaves_out_the_mcp_grants_pi_skips. Pi suite in its own venv: 349 passed, 22 skipped, 1 failed (the same Node 22 test). Each new test fails with its fix reverted.

  • pre-commit run --all-files: clean.

  • Review follow-up (99e0c72): a borrowed session with a restricted value, and a preinstalled runtime that is missing or runs another version, are refused with AgentSeedRejectedError (422); a runtime check that times out stays retryable. New tests cover both and the MCP-only tool-egress filter (an optional direct_http grant opens no host). Pi suite: 353 passed, 22 skipped, and the known test_gym_mcp.mjs failure that needs Node 22. Docs link and import tests: 92 passed.

Rollouts

Egress checks on an OpenSandbox cell, with policies this helper builds:

  • With the model and tool hosts allowed: the allowed Model Server host and tool domain were reachable; nodejs.org, the npm registry, an inference API and GitHub's DNS name were blocked. Without a policy, the same cell reached GitHub, Google and Hugging Face. A preinstalled Pi runtime passed the sandbox_runtime_dir check in a model_only sandbox.
  • Enforcement layer, an A/B probe at f8ccb1b on the same cell: without a policy, TCP to 1.1.1.1:443 and 8.8.8.8:443 connected; with model_only, both timed out and DNS returned no answer. The cell enforces at the IP layer (dns+nft), so a hard-coded IP does not bypass the policy there.

HLE runs (Nemotron 3.5 Super on vLLM, 5 text tasks each), on commits of the georgea/nemo-gym fork that carry this PR's helper and Pi change (the fork's 872067d5e is this PR's first commit, 0183e07, before it was rebased onto main):

  • Pi with model_only (fork 872067d5e): 5/5 rollouts completed, graded and healthy.
  • Pi with model_and_tools and Gym's Tavily server (fork 7cf95c7f4): 5/5 healthy, with the search tools called.
  • Pi on HLE Diamond with model_only (fork ee833ed): 5/5 healthy.

The review changes since then (422 refusals, the profile default, the required-grant refusal, the helper taking the provider) are covered by unit tests; no rollout has run on 0498d0d.

Compatibility and benchmark impact

  • Pi's benchmark profile changes (it shipped in feat(agents): add swappable benchmark profiles for the session harnesses #5550): it now sets network_access: model_only and requires sandbox_runtime_dir, where it used to give the sandbox the provider's open network and install Pi from the internet. A config that uses the profile must supply the runtime directory (or null with an image prebaked at the default path), and a search preset must override with model_and_tools. That is the intended default for HLE-style evaluations; scores from open-network runs are not comparable.
  • pi_agent itself still defaults to network_access: inherit and no sandbox_runtime_dir; configs that don't use the profile are unchanged.
  • Under model_only, a required MCP grant is now refused at seed (422) instead of failing after the sandbox starts.
  • nemo_gym.agents exports two new names, restrict_sandbox_network and SandboxNetworkAccess.

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally, or N/A for docs-only / non-code changes.
  • Documentation added or updated, or N/A with justification. The adapter README describes the new settings.
  • Pre-commit checks pass locally (pre-commit run --all-files).
  • New source files include the required Apache-2.0 SPDX header. nemo_gym/agents/utils/sandbox_network.py and tests/unit_tests/agents/test_sandbox_network.py carry the SPDX header.
  • All commits have DCO sign-off (git commit -s).

Benchmarks whose Resources server supplies no sandbox, such as HLE, have
pi_agent create one per session. pi_sandboxed_agent ran those sandboxes
with model-only egress; pi_agent could not, so a reasoning benchmark moved
to agent sessions would gain open internet.

- network_access (inherit, model_only, model_and_tools) sets an OpenSandbox
  egress policy on a sandbox the agent creates. A borrowed task sandbox
  keeps its owner's network, so a session that borrows one rejects any
  other value. The policy helper, restrict_sandbox_network, lives in
  nemo_gym.agents.utils.sandbox_network and is exported from
  nemo_gym.agents so other session agents can share it.
- sandbox_runtime_dir points setup at a runtime baked into the image and
  checks its version, since a model-only sandbox cannot download Node or Pi.

Signed-off-by: gwarmstrong <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 4, 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.

@gwarmstrong

Copy link
Copy Markdown
Contributor Author

/ok to test 0183e07

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHIP

LGTM — no concerns found. I reviewed all six changed files and traced the affected policy, model/MCP routing, runtime launch, and cleanup paths. The default behavior remains intact, and the restricted modes fail closed before sandbox creation.

I couldn't execute tests in this read-only review. The test results and real smoke rollouts in the PR description are author-provided evidence.

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

restrict_sandbox_network raised ValueError when a restricted
network_access could not be enforced: an explicit provider network
policy as well, a provider without network policies, or an endpoint
the sandbox cannot reach. The seed route answered it with a 500, which
the Environment Server retries, though no attempt can fix the
configuration. The helper now raises AgentSeedRejectedError, still a
ValueError, so every adapter that calls it refuses the seed once with
HTTP 422, before any sandbox is created.

Pi also built its tool egress from every MCP grant, including an
optional one it leaves out at activation, so such a grant at a loopback
URL failed the seed. Egress now covers only the grants Pi keeps.

Signed-off-by: gwarmstrong <[email protected]>
gwarmstrong added a commit to gwarmstrong/Gym that referenced this pull request Nov 4, 2026
gwarmstrong added a commit to gwarmstrong/Gym that referenced this pull request Nov 4, 2026
… with a 422

With NVIDIA-NeMo#5554's restrict_sandbox_network change, a restricted network_access the provider cannot enforce (here an explicit network_policy as well) refuses the seed with HTTP 422 before any sandbox is created, instead of a retried 500.

Signed-off-by: gwarmstrong <[email protected]>
gwarmstrong added a commit to gwarmstrong/Gym that referenced this pull request Nov 4, 2026
gwarmstrong added a commit to gwarmstrong/Gym that referenced this pull request Nov 4, 2026
…th a 422

With NVIDIA-NeMo#5554's restrict_sandbox_network change, a restricted network_access the provider cannot enforce (here an explicit network_policy as well) refuses the seed with HTTP 422 before any sandbox is created, instead of a retried 500.

Signed-off-by: gwarmstrong <[email protected]>
gwarmstrong added a commit to gwarmstrong/Gym that referenced this pull request Nov 4, 2026
gwarmstrong added a commit to gwarmstrong/Gym that referenced this pull request Nov 4, 2026
… with a 422

With NVIDIA-NeMo#5554's restrict_sandbox_network change, a restricted network_access the provider cannot enforce (here an explicit network_policy as well) refuses the seed with HTTP 422 before any sandbox is created, instead of a retried 500.

Signed-off-by: gwarmstrong <[email protected]>
gwarmstrong added a commit to gwarmstrong/Gym that referenced this pull request Nov 4, 2026
gwarmstrong added a commit to gwarmstrong/Gym that referenced this pull request Nov 4, 2026
…ith a 422

With NVIDIA-NeMo#5554's restrict_sandbox_network change, a restricted network_access the provider cannot enforce (here an explicit network_policy as well) refuses the seed with HTTP 422 before any sandbox is created, instead of a retried 500.

Signed-off-by: gwarmstrong <[email protected]>
gwarmstrong added a commit to gwarmstrong/Gym that referenced this pull request Nov 4, 2026
@gwarmstrong

Copy link
Copy Markdown
Contributor Author

/ok to test 8a32f14

@gwarmstrong

Copy link
Copy Markdown
Contributor Author

/ok to test 1cdc63e

Copy link
Copy Markdown
Contributor

✅ CI is green on nvidia-nemo/gym PR #5554 at 1cdc63e912fd — still watching.

Copy link
Copy Markdown
Contributor

💬 CI on 1cdc63e9 has no failing or pending checks, and GitHub reports no merge conflict. The PR is still open; I'll keep watching for the merge.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42097141214

Merged via the queue into NVIDIA-NeMo:main with commit 05719ec Nov 5, 2026
67 checks passed

Copy link
Copy Markdown
Contributor

The PR is no longer an open ready-to-merge PR targeting main.

gwarmstrong added a commit to gwarmstrong/Gym that referenced this pull request Nov 5, 2026
Signed-off-by: gwarmstrong <[email protected]>

NVIDIA-NeMo#5554 was squash-merged, so its files conflicted with this branch's copy of them; main's versions are kept. This PR's own changes are unchanged.
gwarmstrong added a commit to gwarmstrong/Gym that referenced this pull request Nov 5, 2026
Signed-off-by: gwarmstrong <[email protected]>

NVIDIA-NeMo#5554 was squash-merged, so its files conflicted with this branch's copy of them; main's versions are kept. This PR's own changes are unchanged.
gwarmstrong added a commit to gwarmstrong/Gym that referenced this pull request Nov 5, 2026
Signed-off-by: gwarmstrong <[email protected]>

NVIDIA-NeMo#5554 was squash-merged, so its files conflicted with this branch's copy of them; main's versions are kept. This PR's own changes are unchanged.
gwarmstrong added a commit to gwarmstrong/Gym that referenced this pull request Nov 5, 2026
Signed-off-by: gwarmstrong <[email protected]>

NVIDIA-NeMo#5554 was squash-merged, so its files conflicted with this branch's copy of them; main's versions are kept. This PR's own changes are unchanged.
gwarmstrong added a commit to gwarmstrong/Gym that referenced this pull request Nov 5, 2026
Signed-off-by: gwarmstrong <[email protected]>

NVIDIA-NeMo#5554 was squash-merged, so its files conflicted with this branch's copy of them; main's versions are kept. This PR's own changes are unchanged.
gwarmstrong added a commit to gwarmstrong/Gym that referenced this pull request Nov 5, 2026
Brings in NVIDIA-NeMo#5554, which pinned Pi's profile and generalized the profile test
helper; this branch's as-shipped HLE seed test keeps its transports
parameter on top of it. A test that landed on main meanwhile expected the
aime24 math_with_judge Environment Server to grant direct_http, which this
change removes, so it now expects no transports.

Signed-off-by: gwarmstrong <[email protected]>
JeffPengCoder pushed a commit to JeffPengCoder/Gym that referenced this pull request Nov 6, 2026
…A-NeMo#5555)

* feat(pi): restrict the egress of agent-created sandboxes

Benchmarks whose Resources server supplies no sandbox, such as HLE, have
pi_agent create one per session. pi_sandboxed_agent ran those sandboxes
with model-only egress; pi_agent could not, so a reasoning benchmark moved
to agent sessions would gain open internet.

- network_access (inherit, model_only, model_and_tools) sets an OpenSandbox
  egress policy on a sandbox the agent creates. A borrowed task sandbox
  keeps its owner's network, so a session that borrows one rejects any
  other value. The policy helper, restrict_sandbox_network, lives in
  nemo_gym.agents.utils.sandbox_network and is exported from
  nemo_gym.agents so other session agents can share it.
- sandbox_runtime_dir points setup at a runtime baked into the image and
  checks its version, since a model-only sandbox cannot download Node or Pi.

Signed-off-by: gwarmstrong <[email protected]>

* feat(opencode): restrict the egress of agent-created sandboxes

Match pi_agent so reasoning benchmarks without task sandboxes can move
off opencode_sandboxed_agent with the same model-only network:
network_access (inherit, model_only, model_and_tools) sets the
OpenSandbox egress policy on a sandbox OpenCode creates, and a session
that borrows a task sandbox rejects any value other than inherit. It
cannot be combined with sandbox_config.provider_options.network_policy.
The policy comes from the shared restrict_sandbox_network helper,
imported from nemo_gym.agents. The preinstalled runtime path already
exists (sandbox_executable_path).

Signed-off-by: gwarmstrong <[email protected]>

* fix(agents): refuse an unenforceable sandbox network with a 422

restrict_sandbox_network raised ValueError when a restricted
network_access could not be enforced: an explicit provider network
policy as well, a provider without network policies, or an endpoint
the sandbox cannot reach. The seed route answered it with a 500, which
the Environment Server retries, though no attempt can fix the
configuration. The helper now raises AgentSeedRejectedError, still a
ValueError, so every adapter that calls it refuses the seed once with
HTTP 422, before any sandbox is created.

Pi also built its tool egress from every MCP grant, including an
optional one it leaves out at activation, so such a grant at a loopback
URL failed the seed. Egress now covers only the grants Pi keeps.

Signed-off-by: gwarmstrong <[email protected]>

* test(opencode): check that an unenforceable network_access is refused with a 422

With NVIDIA-NeMo#5554's restrict_sandbox_network change, a restricted network_access the provider cannot enforce (here an explicit network_policy as well) refuses the seed with HTTP 422 before any sandbox is created, instead of a retried 500.

Signed-off-by: gwarmstrong <[email protected]>

* docs(agents): tell harness authors to restrict an owned sandbox's egress

The Add or Update a Harness page and the add-harness skill now say that an
adapter that creates its own sandbox exposes network_access and passes the
spec through restrict_sandbox_network, that settings it cannot enforce are
refused with AgentSeedRejectedError, and that a restricted sandbox gets its
runtime by upload or from a preinstalled sandbox_runtime_dir. They also list
the tests, the model_only pairing run, and an egress exit check, so a new
harness cannot leave a sandbox with open egress on a benchmark graded on the
model's own knowledge.

Signed-off-by: gwarmstrong <[email protected]>

* fix(pi): refuse unusable network and runtime settings with a 422

Addresses the review of the Pi egress change:

- A borrowed session with a restricted network_access, and a preinstalled
  runtime that is missing or runs another version, raise
  AgentSeedRejectedError: a final, logged 422 instead of a retried 500. A
  runtime check that hits a transport error or timeout stays retryable.
- A test covers the MCP-only filter on tool egress: an optional
  direct_http grant opens no host.
- The Pi README describes the runtime directory as copied whole (with
  libstdcpp/ on older Alpine), says a restricted sandbox needs it or a
  prebaked default path, recommends absolute_ip_server_types so only the
  model server leaves loopback, and notes that full isolation needs the
  OpenSandbox dns+nft egress mode.
- The harness guide lists agents/utils/sandbox_network.py and the egress
  notes, and the OpenSandbox page points at restrict_sandbox_network.

Signed-off-by: gwarmstrong <[email protected]>

* feat(pi): restrict the benchmark profile's sandbox to the model server

Addresses the second review of the Pi egress change:

- Pi's benchmark profile sets network_access: model_only, like
  pi_sandboxed_agent's profile, so an HLE or GPQA run that uses it as
  shipped no longer gets open internet. A search preset overrides it with
  model_and_tools. sandbox_runtime_dir is required (???), because a
  restricted sandbox cannot download Pi; null keeps an image prebaked at
  the default path.
- restrict_sandbox_network takes the provider instead of its name, so the
  move to SandboxSpec.egress_rules and provider capabilities (NVIDIA-NeMo#5363) only
  changes the helper's body, not its callers.
- The README says a borrowed sandbox relies on its owner's policy.

Signed-off-by: gwarmstrong <[email protected]>

* test(agents): read each profile's network settings from its own file

The profile tests derive which profiles restrict egress and require a runtime directory from the profiles themselves, so a harness that restricts its profile changes only its own files and the stacked PRs do not conflict.

Signed-off-by: gwarmstrong <[email protected]>

* fix(opencode): align network refusals and the helper call with the reviewed Pi change

restrict_sandbox_network now takes the provider, and a borrowed session with a
restricted network_access is refused with AgentSeedRejectedError, so the 422 is
logged like the other adapters'. OpenCode writes every MCP grant into its config,
so its tool egress already matches the grants it keeps. The README notes that a
borrowed sandbox relies on its owner's network policy. The benchmark profile
keeps inherit: OpenCode installs its runtime from GitHub unless the image
supplies sandbox_executable_path and sandbox_executable_sha256.

Signed-off-by: gwarmstrong <[email protected]>

* test(agents): pin each restricted profile in its adapter's own test

Reading the restricted profiles from the files keeps the stacked PRs apart but cannot catch a profile losing model_only. Pi's own seed-test file now expects model_only and a required runtime directory, so removing either fails it, and the shared helper supplies any harness setting a profile requires (a runtime directory, or a baked binary and its checksum) and checks that each one fails at resolve when unset.

Signed-off-by: gwarmstrong <[email protected]>

* feat(opencode): restrict the benchmark profile's sandbox to the model server

The profile sets network_access: model_only, as the reviewed Pi change does, and requires sandbox_executable_path and sandbox_executable_sha256, because a restricted sandbox cannot download OpenCode. Its own test expects model_only and the required binary, so removing either fails it.

Signed-off-by: gwarmstrong <[email protected]>

* fix(agents): refuse a required tool grant that model_only would block

Addresses Yu Yao's review of the Pi egress change:

- restrict_sandbox_network takes the required tool grants and refuses them
  under model_only with AgentSeedRejectedError. The policy blocks their
  hosts, so a session would otherwise fail only after the sandbox and the
  runtime exist, as a retried 5xx. Pi passes its required MCP grants.
- A host written with a trailing dot no longer yields a rule the egress
  sidecar never matches, and provider_options: null is restricted like an
  empty mapping instead of raising a 500.
- Pi's tests cover both restricted values for a borrowed sandbox, a model
  URL that fails to resolve (the provider is closed), and a preinstalled
  runtime that exits nonzero or reports a version prefix.
- The profile comment says that with sandbox_runtime_dir: null the image
  must hold the runtime at the default path with its ready marker.

Signed-off-by: gwarmstrong <[email protected]>

* docs(pi): say which grants a restricted seed refuses

Under model_and_tools, a grant at an unreachable address refuses the seed even when optional, and model_only refuses a required grant.

Signed-off-by: gwarmstrong <[email protected]>

* fix(opencode): refuse a required tool grant that model_only would block

Addresses Yu Yao's review:

- OpenCode passes its required MCP grants to restrict_sandbox_network, so
  under model_only a required grant is refused at seed with a 422 instead
  of failing after the sandbox exists.
- The README and the network_access description say that a restricted
  sandbox needs sandbox_executable_path (or the runtime at the cache path)
  and ripgrep in the image, which grants a restricted seed refuses, and
  that full isolation needs OpenSandbox's dns+nft egress mode.
- The egress test uses a required and an optional MCP grant on different
  hosts plus a direct_http grant that must stay out of the policy, the
  borrowed refusal covers both restricted values, and a route test covers
  the required-grant refusal.

Signed-off-by: gwarmstrong <[email protected]>

---------

Signed-off-by: gwarmstrong <[email protected]>
Co-authored-by: gwarmstrong <[email protected]>
tayunvidia pushed a commit to tayunvidia/Gym that referenced this pull request Nov 6, 2026
…eMo#5556)

* feat(pi): restrict the egress of agent-created sandboxes

Benchmarks whose Resources server supplies no sandbox, such as HLE, have
pi_agent create one per session. pi_sandboxed_agent ran those sandboxes
with model-only egress; pi_agent could not, so a reasoning benchmark moved
to agent sessions would gain open internet.

- network_access (inherit, model_only, model_and_tools) sets an OpenSandbox
  egress policy on a sandbox the agent creates. A borrowed task sandbox
  keeps its owner's network, so a session that borrows one rejects any
  other value. The policy helper, restrict_sandbox_network, lives in
  nemo_gym.agents.utils.sandbox_network and is exported from
  nemo_gym.agents so other session agents can share it.
- sandbox_runtime_dir points setup at a runtime baked into the image and
  checks its version, since a model-only sandbox cannot download Node or Pi.

Signed-off-by: gwarmstrong <[email protected]>

* feat(codex): restrict the egress of agent-created sandboxes

As for pi_agent: network_access sets the OpenSandbox egress policy on a
sandbox Codex creates, and a session that borrows a task sandbox rejects
any other value than inherit. The policy comes from the shared
restrict_sandbox_network helper, imported from nemo_gym.agents, so it
cannot be combined with sandbox_config.provider_options.network_policy.
A model-only sandbox cannot download Node or Codex, so
sandbox_runtime_dir points setup at a runtime baked into the image and
checks that it reports codex-cli <codex_version> instead of installing.

Signed-off-by: gwarmstrong <[email protected]>

* fix(agents): refuse an unenforceable sandbox network with a 422

restrict_sandbox_network raised ValueError when a restricted
network_access could not be enforced: an explicit provider network
policy as well, a provider without network policies, or an endpoint
the sandbox cannot reach. The seed route answered it with a 500, which
the Environment Server retries, though no attempt can fix the
configuration. The helper now raises AgentSeedRejectedError, still a
ValueError, so every adapter that calls it refuses the seed once with
HTTP 422, before any sandbox is created.

Pi also built its tool egress from every MCP grant, including an
optional one it leaves out at activation, so such a grant at a loopback
URL failed the seed. Egress now covers only the grants Pi keeps.

Signed-off-by: gwarmstrong <[email protected]>

* test(codex): check that an unenforceable network_access is refused with a 422

With NVIDIA-NeMo#5554's restrict_sandbox_network change, a restricted network_access the provider cannot enforce (here an explicit network_policy as well) refuses the seed with HTTP 422 before any sandbox is created, instead of a retried 500.

Signed-off-by: gwarmstrong <[email protected]>

* docs(agents): tell harness authors to restrict an owned sandbox's egress

The Add or Update a Harness page and the add-harness skill now say that an
adapter that creates its own sandbox exposes network_access and passes the
spec through restrict_sandbox_network, that settings it cannot enforce are
refused with AgentSeedRejectedError, and that a restricted sandbox gets its
runtime by upload or from a preinstalled sandbox_runtime_dir. They also list
the tests, the model_only pairing run, and an egress exit check, so a new
harness cannot leave a sandbox with open egress on a benchmark graded on the
model's own knowledge.

Signed-off-by: gwarmstrong <[email protected]>

* fix(pi): refuse unusable network and runtime settings with a 422

Addresses the review of the Pi egress change:

- A borrowed session with a restricted network_access, and a preinstalled
  runtime that is missing or runs another version, raise
  AgentSeedRejectedError: a final, logged 422 instead of a retried 500. A
  runtime check that hits a transport error or timeout stays retryable.
- A test covers the MCP-only filter on tool egress: an optional
  direct_http grant opens no host.
- The Pi README describes the runtime directory as copied whole (with
  libstdcpp/ on older Alpine), says a restricted sandbox needs it or a
  prebaked default path, recommends absolute_ip_server_types so only the
  model server leaves loopback, and notes that full isolation needs the
  OpenSandbox dns+nft egress mode.
- The harness guide lists agents/utils/sandbox_network.py and the egress
  notes, and the OpenSandbox page points at restrict_sandbox_network.

Signed-off-by: gwarmstrong <[email protected]>

* feat(pi): restrict the benchmark profile's sandbox to the model server

Addresses the second review of the Pi egress change:

- Pi's benchmark profile sets network_access: model_only, like
  pi_sandboxed_agent's profile, so an HLE or GPQA run that uses it as
  shipped no longer gets open internet. A search preset overrides it with
  model_and_tools. sandbox_runtime_dir is required (???), because a
  restricted sandbox cannot download Pi; null keeps an image prebaked at
  the default path.
- restrict_sandbox_network takes the provider instead of its name, so the
  move to SandboxSpec.egress_rules and provider capabilities (NVIDIA-NeMo#5363) only
  changes the helper's body, not its callers.
- The README says a borrowed sandbox relies on its owner's policy.

Signed-off-by: gwarmstrong <[email protected]>

* test(agents): read each profile's network settings from its own file

The profile tests derive which profiles restrict egress and require a runtime directory from the profiles themselves, so a harness that restricts its profile changes only its own files and the stacked PRs do not conflict.

Signed-off-by: gwarmstrong <[email protected]>

* fix(codex): restrict the benchmark profile and open only kept tool hosts

The benchmark profile sets network_access: model_only and requires
sandbox_runtime_dir, since a restricted sandbox cannot download Codex. Tool
egress comes only from MCP grants Codex writes into config.toml, so an optional
grant it leaves out for its name opens no host. restrict_sandbox_network takes
the provider, and a borrowed session with a restricted value is refused with
AgentSeedRejectedError. The README notes that a borrowed sandbox relies on its
owner's network policy.

Signed-off-by: gwarmstrong <[email protected]>

* test(agents): pin each restricted profile in its adapter's own test

Reading the restricted profiles from the files keeps the stacked PRs apart but cannot catch a profile losing model_only. Pi's own seed-test file now expects model_only and a required runtime directory, so removing either fails it, and the shared helper supplies any harness setting a profile requires (a runtime directory, or a baked binary and its checksum) and checks that each one fails at resolve when unset.

Signed-off-by: gwarmstrong <[email protected]>

* test(codex): pin the benchmark profile's model_only setting

This adapter's own test expects its profile to set network_access: model_only, with the required runtime where the harness downloads one, so removing it fails the test.

Signed-off-by: gwarmstrong <[email protected]>

* fix(agents): refuse a required tool grant that model_only would block

Addresses Yu Yao's review of the Pi egress change:

- restrict_sandbox_network takes the required tool grants and refuses them
  under model_only with AgentSeedRejectedError. The policy blocks their
  hosts, so a session would otherwise fail only after the sandbox and the
  runtime exist, as a retried 5xx. Pi passes its required MCP grants.
- A host written with a trailing dot no longer yields a rule the egress
  sidecar never matches, and provider_options: null is restricted like an
  empty mapping instead of raising a 500.
- Pi's tests cover both restricted values for a borrowed sandbox, a model
  URL that fails to resolve (the provider is closed), and a preinstalled
  runtime that exits nonzero or reports a version prefix.
- The profile comment says that with sandbox_runtime_dir: null the image
  must hold the runtime at the default path with its ready marker.

Signed-off-by: gwarmstrong <[email protected]>

* docs(pi): say which grants a restricted seed refuses

Under model_and_tools, a grant at an unreachable address refuses the seed even when optional, and model_only refuses a required grant.

Signed-off-by: gwarmstrong <[email protected]>

* fix(codex): refuse unusable runtimes and required grants with a 422

Addresses Yu Yao's review:

- The preinstalled-runtime check runs with CODEX_HOME under the session
  directory, so it writes nothing into the task's home, and checks for
  Python 3.8+ first, as the installer does. A runtime that is missing, runs
  another version (exact match) or finds no usable Python refuses the seed
  with AgentSeedRejectedError; a transport error or timeout stays retryable.
- sandbox_transport.py postpones annotation evaluation, so it imports on
  the Python 3.8 and 3.9 the README and installer allow (checked under both).
- Codex passes its required MCP grants to restrict_sandbox_network, so
  model_only refuses them at seed instead of failing after setup.
- The README says how to build sandbox_runtime_dir, that the image needs
  bash and python3, that the setting also applies to a borrowed sandbox
  (checked, never stopped), which grants a restricted seed refuses, and
  that full isolation needs OpenSandbox's dns+nft egress mode.
- Tests: several grants (required, optional, direct_http) in the egress
  test, both restricted values for the borrowed refusal, a route test per
  refusal cause with the provider closed and no session record left, and a
  runtime-check table (prefix, failed run, timeout, runtime used).

Signed-off-by: gwarmstrong <[email protected]>

---------

Signed-off-by: gwarmstrong <[email protected]>
Co-authored-by: gwarmstrong <[email protected]>
svcnemo-autobot pushed a commit to svcnemo-autobot/Gym that referenced this pull request Nov 6, 2026
…A-NeMo#5557)

* feat(pi): restrict the egress of agent-created sandboxes

Benchmarks whose Resources server supplies no sandbox, such as HLE, have
pi_agent create one per session. pi_sandboxed_agent ran those sandboxes
with model-only egress; pi_agent could not, so a reasoning benchmark moved
to agent sessions would gain open internet.

- network_access (inherit, model_only, model_and_tools) sets an OpenSandbox
  egress policy on a sandbox the agent creates. A borrowed task sandbox
  keeps its owner's network, so a session that borrows one rejects any
  other value. The policy helper, restrict_sandbox_network, lives in
  nemo_gym.agents.utils.sandbox_network and is exported from
  nemo_gym.agents so other session agents can share it.
- sandbox_runtime_dir points setup at a runtime baked into the image and
  checks its version, since a model-only sandbox cannot download Node or Pi.

Signed-off-by: gwarmstrong <[email protected]>

* feat(openclaw): restrict the egress of agent-created sandboxes

As for pi_agent: network_access (inherit, model_only, model_and_tools)
sets the OpenSandbox egress policy on a sandbox OpenClaw creates, through
restrict_sandbox_network from nemo_gym.agents. A session that borrows a
task sandbox rejects any other value than inherit, and the setting cannot
be combined with sandbox_config.provider_options.network_policy. A
model-only sandbox cannot download Node or OpenClaw, so
sandbox_runtime_dir points setup at a runtime baked into the image and
checks the version its package declares instead of installing; a
mismatch fails setup.

Signed-off-by: gwarmstrong <[email protected]>

* fix(agents): refuse an unenforceable sandbox network with a 422

restrict_sandbox_network raised ValueError when a restricted
network_access could not be enforced: an explicit provider network
policy as well, a provider without network policies, or an endpoint
the sandbox cannot reach. The seed route answered it with a 500, which
the Environment Server retries, though no attempt can fix the
configuration. The helper now raises AgentSeedRejectedError, still a
ValueError, so every adapter that calls it refuses the seed once with
HTTP 422, before any sandbox is created.

Pi also built its tool egress from every MCP grant, including an
optional one it leaves out at activation, so such a grant at a loopback
URL failed the seed. Egress now covers only the grants Pi keeps.

Signed-off-by: gwarmstrong <[email protected]>

* test(openclaw): check that an unenforceable network_access is refused with a 422

With NVIDIA-NeMo#5554's restrict_sandbox_network change, a restricted network_access the provider cannot enforce (here an explicit network_policy as well) refuses the seed with HTTP 422 before any sandbox is created, instead of a retried 500.

Signed-off-by: gwarmstrong <[email protected]>

* docs(agents): tell harness authors to restrict an owned sandbox's egress

The Add or Update a Harness page and the add-harness skill now say that an
adapter that creates its own sandbox exposes network_access and passes the
spec through restrict_sandbox_network, that settings it cannot enforce are
refused with AgentSeedRejectedError, and that a restricted sandbox gets its
runtime by upload or from a preinstalled sandbox_runtime_dir. They also list
the tests, the model_only pairing run, and an egress exit check, so a new
harness cannot leave a sandbox with open egress on a benchmark graded on the
model's own knowledge.

Signed-off-by: gwarmstrong <[email protected]>

* fix(pi): refuse unusable network and runtime settings with a 422

Addresses the review of the Pi egress change:

- A borrowed session with a restricted network_access, and a preinstalled
  runtime that is missing or runs another version, raise
  AgentSeedRejectedError: a final, logged 422 instead of a retried 500. A
  runtime check that hits a transport error or timeout stays retryable.
- A test covers the MCP-only filter on tool egress: an optional
  direct_http grant opens no host.
- The Pi README describes the runtime directory as copied whole (with
  libstdcpp/ on older Alpine), says a restricted sandbox needs it or a
  prebaked default path, recommends absolute_ip_server_types so only the
  model server leaves loopback, and notes that full isolation needs the
  OpenSandbox dns+nft egress mode.
- The harness guide lists agents/utils/sandbox_network.py and the egress
  notes, and the OpenSandbox page points at restrict_sandbox_network.

Signed-off-by: gwarmstrong <[email protected]>

* feat(pi): restrict the benchmark profile's sandbox to the model server

Addresses the second review of the Pi egress change:

- Pi's benchmark profile sets network_access: model_only, like
  pi_sandboxed_agent's profile, so an HLE or GPQA run that uses it as
  shipped no longer gets open internet. A search preset overrides it with
  model_and_tools. sandbox_runtime_dir is required (???), because a
  restricted sandbox cannot download Pi; null keeps an image prebaked at
  the default path.
- restrict_sandbox_network takes the provider instead of its name, so the
  move to SandboxSpec.egress_rules and provider capabilities (NVIDIA-NeMo#5363) only
  changes the helper's body, not its callers.
- The README says a borrowed sandbox relies on its owner's policy.

Signed-off-by: gwarmstrong <[email protected]>

* test(agents): read each profile's network settings from its own file

The profile tests derive which profiles restrict egress and require a runtime directory from the profiles themselves, so a harness that restricts its profile changes only its own files and the stacked PRs do not conflict.

Signed-off-by: gwarmstrong <[email protected]>

* fix(openclaw): restrict the benchmark profile to the model server

The benchmark profile sets network_access: model_only and requires
sandbox_runtime_dir, since a restricted sandbox cannot download OpenClaw.
restrict_sandbox_network takes the provider, and a borrowed session with a
restricted value is refused with AgentSeedRejectedError. OpenClaw writes every
MCP grant into its config and probes it, so its tool egress already matches.
The README notes that a borrowed sandbox relies on its owner's network policy.

Signed-off-by: gwarmstrong <[email protected]>

* test(agents): pin each restricted profile in its adapter's own test

Reading the restricted profiles from the files keeps the stacked PRs apart but cannot catch a profile losing model_only. Pi's own seed-test file now expects model_only and a required runtime directory, so removing either fails it, and the shared helper supplies any harness setting a profile requires (a runtime directory, or a baked binary and its checksum) and checks that each one fails at resolve when unset.

Signed-off-by: gwarmstrong <[email protected]>

* test(openclaw): pin the benchmark profile's model_only setting

This adapter's own test expects its profile to set network_access: model_only, with the required runtime where the harness downloads one, so removing it fails the test.

Signed-off-by: gwarmstrong <[email protected]>

* fix(agents): refuse a required tool grant that model_only would block

Addresses Yu Yao's review of the Pi egress change:

- restrict_sandbox_network takes the required tool grants and refuses them
  under model_only with AgentSeedRejectedError. The policy blocks their
  hosts, so a session would otherwise fail only after the sandbox and the
  runtime exist, as a retried 5xx. Pi passes its required MCP grants.
- A host written with a trailing dot no longer yields a rule the egress
  sidecar never matches, and provider_options: null is restricted like an
  empty mapping instead of raising a 500.
- Pi's tests cover both restricted values for a borrowed sandbox, a model
  URL that fails to resolve (the provider is closed), and a preinstalled
  runtime that exits nonzero or reports a version prefix.
- The profile comment says that with sandbox_runtime_dir: null the image
  must hold the runtime at the default path with its ready marker.

Signed-off-by: gwarmstrong <[email protected]>

* docs(pi): say which grants a restricted seed refuses

Under model_and_tools, a grant at an unreachable address refuses the seed even when optional, and model_only refuses a required grant.

Signed-off-by: gwarmstrong <[email protected]>

* fix(openclaw): check a preinstalled runtime fully and refuse it with a 422

Addresses Yu Yao's review:

- The preinstalled-runtime check now checks the runtime's Node is 22.19.0
  or newer, runs the CLI's --version with a private home (so an incomplete
  runtime fails at seed, not at activation, and the task's home stays
  untouched), then compares the version the package declares exactly. A
  failed check or another version refuses the seed with
  AgentSeedRejectedError; a transport error or timeout stays retryable.
- OpenClaw passes its required MCP grants to restrict_sandbox_network, so
  model_only refuses them at seed instead of after the 120 s probe.
- The README says how to build sandbox_runtime_dir and what the image
  needs, which grants a restricted seed refuses, that an optional grant
  still costs a probe under model_only, and that full isolation needs
  OpenSandbox's dns+nft egress mode.
- Tests: several grants plus one declared in the agent config in the egress
  test, both restricted values for the borrowed refusal, a route test per
  refusal cause, a runtime-check table (prefix, failed check, timeout), and
  the exact check command run under a real node.

Signed-off-by: gwarmstrong <[email protected]>

---------

Signed-off-by: gwarmstrong <[email protected]>
Co-authored-by: gwarmstrong <[email protected]>
svcnemo-autobot pushed a commit to svcnemo-autobot/Gym that referenced this pull request Nov 6, 2026
…NeMo#5558)

* feat(pi): restrict the egress of agent-created sandboxes

Benchmarks whose Resources server supplies no sandbox, such as HLE, have
pi_agent create one per session. pi_sandboxed_agent ran those sandboxes
with model-only egress; pi_agent could not, so a reasoning benchmark moved
to agent sessions would gain open internet.

- network_access (inherit, model_only, model_and_tools) sets an OpenSandbox
  egress policy on a sandbox the agent creates. A borrowed task sandbox
  keeps its owner's network, so a session that borrows one rejects any
  other value. The policy helper, restrict_sandbox_network, lives in
  nemo_gym.agents.utils.sandbox_network and is exported from
  nemo_gym.agents so other session agents can share it.
- sandbox_runtime_dir points setup at a runtime baked into the image and
  checks its version, since a model-only sandbox cannot download Node or Pi.

Signed-off-by: gwarmstrong <[email protected]>

* feat(hermes): restrict the egress of agent-created sandboxes

As in pi_agent, network_access (inherit, model_only, model_and_tools) sets
the OpenSandbox egress policy on a sandbox Hermes creates. It uses
restrict_sandbox_network, imported from nemo_gym.agents, with the model URL
that the sandbox reachability check already resolves. A session that
borrows a task sandbox rejects any other value than inherit through
AgentSeedRejectedError, and the setting cannot be combined with
sandbox_config.provider_options.network_policy. Hermes already reuses a
runtime baked into the image at its commit-keyed path, which a restricted
sandbox needs because it cannot install one.

Signed-off-by: gwarmstrong <[email protected]>

* fix(agents): refuse an unenforceable sandbox network with a 422

restrict_sandbox_network raised ValueError when a restricted
network_access could not be enforced: an explicit provider network
policy as well, a provider without network policies, or an endpoint
the sandbox cannot reach. The seed route answered it with a 500, which
the Environment Server retries, though no attempt can fix the
configuration. The helper now raises AgentSeedRejectedError, still a
ValueError, so every adapter that calls it refuses the seed once with
HTTP 422, before any sandbox is created.

Pi also built its tool egress from every MCP grant, including an
optional one it leaves out at activation, so such a grant at a loopback
URL failed the seed. Egress now covers only the grants Pi keeps.

Signed-off-by: gwarmstrong <[email protected]>

* test(hermes): check that an unenforceable network_access is refused with a 422

With NVIDIA-NeMo#5554's restrict_sandbox_network change, a restricted network_access the provider cannot enforce (here an explicit network_policy as well) refuses the seed with HTTP 422 before any sandbox is created, instead of a retried 500.

Signed-off-by: gwarmstrong <[email protected]>

* docs(agents): tell harness authors to restrict an owned sandbox's egress

The Add or Update a Harness page and the add-harness skill now say that an
adapter that creates its own sandbox exposes network_access and passes the
spec through restrict_sandbox_network, that settings it cannot enforce are
refused with AgentSeedRejectedError, and that a restricted sandbox gets its
runtime by upload or from a preinstalled sandbox_runtime_dir. They also list
the tests, the model_only pairing run, and an egress exit check, so a new
harness cannot leave a sandbox with open egress on a benchmark graded on the
model's own knowledge.

Signed-off-by: gwarmstrong <[email protected]>

* fix(pi): refuse unusable network and runtime settings with a 422

Addresses the review of the Pi egress change:

- A borrowed session with a restricted network_access, and a preinstalled
  runtime that is missing or runs another version, raise
  AgentSeedRejectedError: a final, logged 422 instead of a retried 500. A
  runtime check that hits a transport error or timeout stays retryable.
- A test covers the MCP-only filter on tool egress: an optional
  direct_http grant opens no host.
- The Pi README describes the runtime directory as copied whole (with
  libstdcpp/ on older Alpine), says a restricted sandbox needs it or a
  prebaked default path, recommends absolute_ip_server_types so only the
  model server leaves loopback, and notes that full isolation needs the
  OpenSandbox dns+nft egress mode.
- The harness guide lists agents/utils/sandbox_network.py and the egress
  notes, and the OpenSandbox page points at restrict_sandbox_network.

Signed-off-by: gwarmstrong <[email protected]>

* feat(pi): restrict the benchmark profile's sandbox to the model server

Addresses the second review of the Pi egress change:

- Pi's benchmark profile sets network_access: model_only, like
  pi_sandboxed_agent's profile, so an HLE or GPQA run that uses it as
  shipped no longer gets open internet. A search preset overrides it with
  model_and_tools. sandbox_runtime_dir is required (???), because a
  restricted sandbox cannot download Pi; null keeps an image prebaked at
  the default path.
- restrict_sandbox_network takes the provider instead of its name, so the
  move to SandboxSpec.egress_rules and provider capabilities (NVIDIA-NeMo#5363) only
  changes the helper's body, not its callers.
- The README says a borrowed sandbox relies on its owner's policy.

Signed-off-by: gwarmstrong <[email protected]>

* test(agents): read each profile's network settings from its own file

The profile tests derive which profiles restrict egress and require a runtime directory from the profiles themselves, so a harness that restricts its profile changes only its own files and the stacked PRs do not conflict.

Signed-off-by: gwarmstrong <[email protected]>

* fix(hermes): restrict the benchmark profile to the model server

The benchmark profile sets network_access: model_only: the Agent Server builds
and uploads Hermes's runtime, so setup needs no sandbox network, and the README
row that said the image must bake it in is corrected. restrict_sandbox_network
takes the provider. The README notes that a borrowed sandbox relies on its
owner's network policy.

Signed-off-by: gwarmstrong <[email protected]>

* test(agents): pin each restricted profile in its adapter's own test

Reading the restricted profiles from the files keeps the stacked PRs apart but cannot catch a profile losing model_only. Pi's own seed-test file now expects model_only and a required runtime directory, so removing either fails it, and the shared helper supplies any harness setting a profile requires (a runtime directory, or a baked binary and its checksum) and checks that each one fails at resolve when unset.

Signed-off-by: gwarmstrong <[email protected]>

* test(hermes): pin the benchmark profile's model_only setting

This adapter's own test expects its profile to set network_access: model_only, with the required runtime where the harness downloads one, so removing it fails the test.

Signed-off-by: gwarmstrong <[email protected]>

* fix(agents): refuse a required tool grant that model_only would block

Addresses Yu Yao's review of the Pi egress change:

- restrict_sandbox_network takes the required tool grants and refuses them
  under model_only with AgentSeedRejectedError. The policy blocks their
  hosts, so a session would otherwise fail only after the sandbox and the
  runtime exist, as a retried 5xx. Pi passes its required MCP grants.
- A host written with a trailing dot no longer yields a rule the egress
  sidecar never matches, and provider_options: null is restricted like an
  empty mapping instead of raising a 500.
- Pi's tests cover both restricted values for a borrowed sandbox, a model
  URL that fails to resolve (the provider is closed), and a preinstalled
  runtime that exits nonzero or reports a version prefix.
- The profile comment says that with sandbox_runtime_dir: null the image
  must hold the runtime at the default path with its ready marker.

Signed-off-by: gwarmstrong <[email protected]>

* docs(pi): say which grants a restricted seed refuses

Under model_and_tools, a grant at an unreachable address refuses the seed even when optional, and model_only refuses a required grant.

Signed-off-by: gwarmstrong <[email protected]>

* fix(hermes): refuse unreachable model URLs and required grants with a 422

Addresses Yu Yao's review:

- A model URL the sandbox cannot reach (loopback without use_absolute_ip)
  now refuses the seed with AgentSeedRejectedError, a final 422, instead of
  a retried 500; it fails the same way on every attempt.
- Hermes passes its required MCP grants to restrict_sandbox_network, so
  model_only refuses them at seed instead of failing inside the runner.
- The network_access description now says the Agent Server builds and
  uploads Hermes's runtime, matching the README, and the README row lists
  the refusals and the dns+nft caveat.
- Tests go through /v1/agent_sessions for the borrowed refusal (both
  restricted values) and for each unenforceable cause (an explicit policy,
  a provider without policies, a required grant), checking the provider is
  closed and no session record is left. The egress test adds a required
  grant, a configured grant and a direct_http grant, and checks the model
  host the runner's payload calls is the one the policy allows.

Signed-off-by: gwarmstrong <[email protected]>

---------

Signed-off-by: gwarmstrong <[email protected]>
Co-authored-by: gwarmstrong <[email protected]>
gwarmstrong added a commit to gwarmstrong/Gym that referenced this pull request Nov 7, 2026
Main's egress change (NVIDIA-NeMo#5554, NVIDIA-NeMo#5555) builds an owned sandbox's network policy from the Gym model server's URL. With model_base_url set and no model_server, that read failed on None, so Pi and OpenCode could not seed a sandbox they create, whatever network_access was. The policy now takes the direct endpoint in that case, so model_only opens the endpoint's host. Each adapter's tests seed an owned sandbox with a direct endpoint under inherit and model_only; they fail without this change.

Signed-off-by: gwarmstrong <[email protected]>
bpritam14 pushed a commit to bpritam14/Gym-evaluation that referenced this pull request Nov 13, 2026
…_agent sessions (NVIDIA-NeMo#5702)

* feat(pi): opt-ins to run Pi in a task sandbox as a harness started there

Benchmarks that grade a harness started inside the task container (Harbor's
agents) need Pi to run with its own tools and prompt, call the benchmark's
model endpoint, and leave logs where the verifier side collects them. Pi's
sandbox sessions could only call a Gym model server with Gym's runtime
guards, and they lost Pi's context-limit outcomes with Pi 0.80.10.

All new settings are off or empty by default, so existing configs behave
as before:

- model_base_url and model_api_key: Pi calls an OpenAI-compatible endpoint
  directly from the sandbox instead of a Gym model server (set exactly one).
  Gym does not capture those calls.
- thinking_level_map and provider_compat for the generated provider, so
  that `--thinking max` can send chat reasoning_effort "max"; settings
  merged recursively over Gym's settings.json (for example retry counts).
- sandbox_env, and sandbox_runtime_guards: false to run Pi's own tools and
  system prompt without Gym's bash cap and prompt note.
- session_prompt_cache_key: one prompt_cache_key per session on every call,
  so a gateway that routes on it keeps the session on one replica.
- sandbox_logs_dir and log_requests: Pi's JSON events (pi.txt), its stderr
  and a per-request log without the conversation in a sandbox directory
  such as Harbor's /logs/agent.
- raise_oom_score_adj: Pi and its tools become the memory-cgroup OOM
  killer's preferred victims, not the exec daemon or the supervisor.
- verify_after_agent_error: a Pi run that failed while its sandbox still
  runs and answers is returned as a gradable failed response, as Harbor
  grades after any agent exit, unless its terminal error is a transient
  model-endpoint failure (after Pi's own retries) or cleanup is unconfirmed.

The runner drops Pi's streaming message_update and tool_execution_update
events, which repeat the whole partial message on every delta, so long
turns no longer grow the event log quadratically. Pi 0.80.10 routes
extension console output to stderr in JSON mode, so outcome.mjs writes its
records to a session file that the runner appends to the event log;
before, context-limit outcomes never reached the adapter in sandbox
sessions. Local runs keep printing them.

The task's HOME, the agent timeout from the task metadata and the
runner's cleanup on capture errors are upstream behaviour and unchanged.

Signed-off-by: gwarmstrong <[email protected]>

* feat(opencode): opt-in direct model endpoint for sandbox sessions

opencode_agent sandbox sessions could only call a Gym model server. A
benchmark that grades a harness started in the task container, as
Harbor runs OpenCode, has the harness call the model endpoint itself,
and routing those calls through a Gym model server changes the requests
the endpoint sees.

model_base_url and model_api_key (both unset by default) point the
session's OpenAI-compatible provider at an endpoint the sandbox reaches,
sending `model` as the model ID; set exactly one of model_server and
model_base_url. Gym does not capture those calls, so the model-call
correlation plugin is not loaded for them. Sessions with a model server
and local calls are unchanged.

Signed-off-by: gwarmstrong <[email protected]>

* feat(opencode): opt-in model request settings for sandbox sessions

A sandbox session's provider sent no reasoning effort, replayed reasoning
only as reasoning_content, capped every call at max_output_tokens and
told OpenCode the model's size, so it compacted before the endpoint's
real limit. A harness started in a task container with its own model
config does none of that, and some endpoints read the replayed reasoning
from another field.

Four settings, whose defaults keep today's requests:

- reasoning_effort: the model's reasoningEffort option, sent as chat
  reasoning_effort on every request.
- interleaved_reasoning_field: the assistant-message field that replays
  each turn's reasoning (default reasoning_content).
- output_token_policy: remaining_context loads a plugin that drops
  max_tokens from the session provider's requests, so the endpoint picks
  the output budget, as opencode_sandboxed_agent's policy of that name
  does.
- declare_model_limits: false leaves the model's size unknown to
  OpenCode, which then compacts only when the endpoint reports an
  overflow.

Signed-off-by: gwarmstrong <[email protected]>

* feat(opencode): opt-in root workdir and argv prompt for sandbox sessions

Two gaps kept a sandbox session from running OpenCode the way a harness
started in the task container does:

- Task images without a WORKDIR start in /, and sessions rejected that
  workdir because the adapter's runtime and session files under /tmp sit
  inside it. allow_root_workdir accepts exactly / (the files stay under
  /tmp, as a harness's own files do there); /tmp and the adapter's own
  directories are still rejected, and other workdirs keep the full
  overlap check.
- A launcher that passes the instruction as one argument, as Harbor
  0.24's opencode agent does, makes `opencode run` wrap it in double
  quotes (inner quotes escaped) before the model sees it. Sessions send
  the instruction on stdin, unquoted. argv_prompt_quoting sends the text
  OpenCode builds from that argument instead.

Both are off by default.

Signed-off-by: gwarmstrong <[email protected]>

* feat(opencode): grade a failed run while its sandbox still runs

Harbor runs the verifier after any agent exit that is not a timeout, so a
trial whose agent died while its sandbox still answers is graded, not
rerun. opencode_agent sessions raised an execution error for every failed
OpenCode run (a nonzero exit, an error on an assistant turn, no terminal
result), so the Environment Server skipped verification and retried the
episode from scratch: an OpenCode the kernel's OOM kill hit, one whose
own pkill hit it, or a request the endpoint rejected.

verify_after_agent_error (off by default) returns such a run as a
`failed` response (`incomplete` when it also hit its time limit), with the
error in metadata.graded_agent_error, which Resources grades as a nonzero
agent exit. It applies only when the supervisor confirmed cleanup, the
run's session export was read, the last assistant turn's error is not a
transient model-endpoint failure (OpenCode's retryable APIError: 429,
5xx, reset or lost connections, header and stream timeouts) and the
sandbox still reports running and answers a probe command. Anything else
stays an execution error and is retried.

raise_oom_score_adj (off by default) makes OpenCode the OOM killer's
preferred victim in its sandbox, as codex_agent's setting of that name
does: the runner raises its own oom_score_adj, which OpenCode and its
tools inherit, to 1000, or to 0 when the sandbox starts it below zero.
The exec daemon and the supervisor keep the sandbox's own score.

Signed-off-by: gwarmstrong <[email protected]>

* feat(claude-code): opt-in instruction on stdin for sandbox sessions

Sandbox sessions pass the instruction to `claude -p` as an argument
after `--`. Harbor 0.24's claude-code agent pipes it on stdin instead,
and on a command line the task's own words are a target: an agent that
runs `pkill -f <word from its task>` stops its own Claude Code.

instruction_on_stdin (off by default) leaves the instruction out of argv
and has the runner feed it to the CLI on stdin from a session file.
Without it, the runner keeps stdin empty, as before.

Signed-off-by: gwarmstrong <[email protected]>

* feat(claude-code): opt-in effort, output cap and client environment

Running Claude Code against a self-hosted model the way its provider's
Claude Code guide configures it needs three client settings the agent
could not express: the reasoning effort (`--effort`, which Harbor passes
from its reasoning_effort), the per-call output cap
(CLAUDE_CODE_MAX_OUTPUT_TOKENS) and further client environment such as
API_TIMEOUT_MS or CLAUDE_CODE_AUTO_COMPACT_WINDOW. A settings file on the
agent host could carry environment, but not from a run config, and not
the CLI flag.

reasoning_effort, max_output_tokens and extra_env (all unset by default)
apply to local and sandbox launches alike. extra_env rejects the
variables the agent sets itself (endpoint, credentials, model,
CLAUDE_CONFIG_DIR, the output cap), and YAML integers become strings.

Signed-off-by: gwarmstrong <[email protected]>

* feat(claude-code): opt-in root workdir for sandbox sessions

A task image without a WORKDIR lends "/" as its working directory, and
sandbox sessions refuse it because the runtime and session files under
/tmp sit inside it, so every such trial fails at session start while a
harness started in the container runs there.

allow_root_workdir (off by default) accepts exactly "/". The runtime and
session files stay under /tmp; /tmp itself, the adapter's own
directories and relative or `..` paths are still refused.

Signed-off-by: gwarmstrong <[email protected]>

* feat(claude-code): opt-in Harbor system-dependency step for sandbox sessions

Before Harbor 0.24 installs Claude Code in a task container, its
claude-code agent runs ensure_system_dependencies for curl, bash, nodejs,
npm and procps: each one whose commands are missing is installed as root
with the first package manager found. Agents graded under Harbor
therefore have node, npm, ps and pkill even where the task image lacks
them, and a sandbox session that skips the step runs Claude Code in a
different environment.

harbor_system_dependencies (off by default) runs the same decisions as
one POSIX sh script (system_dependencies.py: Harbor's checks, package
names, manager order and install command lines, logged line by line)
before the session installs Claude Code, bounded by
system_dependencies_timeout_seconds (default 1800). Where Harbor errors
the trial on a failed install, the session logs the failure and runs
Claude Code anyway. The script's tests run it under real shells with
stand-in package managers.

Signed-off-by: gwarmstrong <[email protected]>

* refactor(pi): read the outcome records from stdout, as main's outcome extension writes them

Signed-off-by: gwarmstrong <[email protected]>

* fix(agents): leave model errors the agent reported to the outcome policy

Signed-off-by: gwarmstrong <[email protected]>

* fix(agents): keep setup failures ungraded after an agent error

With verify_after_agent_error, Pi and OpenCode graded any failed run while
the sandbox still ran. A run the harness runner could not start (exit 125,
126 or 127), a Pi run whose Gym MCP tools did not load (exit 78), or an
OpenCode run whose required Gym MCP tools did not connect or were never
confirmed is a setup failure: it now stays an execution error and is
retried, never graded as the agent's result.

Signed-off-by: gwarmstrong <[email protected]>

* feat(agents): add swappable benchmark profiles for the session harnesses

The deprecated pi_sandboxed_agent and opencode_sandboxed_agent each ship a
configs/benchmark.yaml profile. A caller that composes a benchmark itself,
such as an evaluation framework that runs HLE, loads that profile instead
of naming a Resources server. The session harnesses that replace them had
no such profile, so moving those callers off the deprecated agents meant
copying the `resources_server.name: ???` binding into the caller, where
some config systems reject a mandatory-missing value.

Add the same profile to pi_agent, opencode_agent, codex_agent,
openclaw_agent, hermes_agent and claude_code_agent, at
configs/profiles/benchmark.yaml. Each leaves the Resources server unset, so
Gym composes the agent onto the benchmark's own agent instance, and each
session creates its own sandbox through the `sandbox` provider at an
absolute address. The Claude Code profile also points the CLI at the
`policy_model` Gym model server. Image, limits and prompts stay with the
caller. Agent discovery reads only the top level of configs/, so, like
opencode_agent's permission profiles, these are not listed as standalone
agent variants.

Signed-off-by: gwarmstrong <[email protected]>

* feat(env): grant MCP tools of extra tool servers to session agents

A session agent got tool grants only from its episode's own Resources
server, so the HLE search presets, which add a Tavily server through
tool_servers, had no session path and stayed on the deprecated sandboxed
agents.

single_agent_turn now takes tool_servers: each episode seeds its own
session on every listed Resources server, with the episode's task data,
grants that server's MCP tools as a required MCPToolAccess, and closes
the session at cleanup. Unset, it falls back to the bound agent's
tool_servers, declared on the base agent config, so a pairing moved off
the legacy_agent relay keeps the tool servers its /run seeded, and a
harness overlay can add search without naming generated instances. As
with the Resources server's own MCP grant, an episode that grants one
restarts from its input after a crash.

Signed-off-by: gwarmstrong <[email protected]>

* feat(pi): restrict the egress of agent-created sandboxes

Benchmarks whose Resources server supplies no sandbox, such as HLE, have
pi_agent create one per session. pi_sandboxed_agent ran those sandboxes
with model-only egress; pi_agent could not, so a reasoning benchmark moved
to agent sessions would gain open internet.

- network_access (inherit, model_only, model_and_tools) sets an OpenSandbox
  egress policy on a sandbox the agent creates. A borrowed task sandbox
  keeps its owner's network, so a session that borrows one rejects any
  other value. The policy helper, restrict_sandbox_network, lives in
  nemo_gym.agents.utils.sandbox_network and is exported from
  nemo_gym.agents so other session agents can share it.
- sandbox_runtime_dir points setup at a runtime baked into the image and
  checks its version, since a model-only sandbox cannot download Node or Pi.

Signed-off-by: gwarmstrong <[email protected]>

* feat(opencode): restrict the egress of agent-created sandboxes

Match pi_agent so reasoning benchmarks without task sandboxes can move
off opencode_sandboxed_agent with the same model-only network:
network_access (inherit, model_only, model_and_tools) sets the
OpenSandbox egress policy on a sandbox OpenCode creates, and a session
that borrows a task sandbox rejects any value other than inherit. It
cannot be combined with sandbox_config.provider_options.network_policy.
The policy comes from the shared restrict_sandbox_network helper,
imported from nemo_gym.agents. The preinstalled runtime path already
exists (sandbox_executable_path).

Signed-off-by: gwarmstrong <[email protected]>

* fix(env): refuse to start with a tool server that cannot serve MCP tools

Startup now also rejects a tool server that is not a Resources server, the
episode's own Resources server, and a Resources server without
expose_tools_over_mcp, each of which otherwise failed every episode.

The partner_if_dispatcher and nooa_agent tests build this server from a bare
client, so they now pass tool_servers=[] instead of reading their agent's.
The README separates the Resources transports from tool-server grants and
says every seeded session is closed.

Signed-off-by: gwarmstrong <[email protected]>

* fix(agents): let the benchmark profiles run HLE episodes

Composed onto HLE, every session harness rejected the first seed with a
422. HLE's Environment Server grants the agent its Resources server over
direct_http, which no session harness can use; HLE Diamond, GPQA and
APEX Shortlist do the same. The judge offers the agent no tools, so each
adapter README now gives the pairing setting that clears the grant,
`resources_tool_transports: []` under the benchmark's Environment Server.

The profiles also fill the gaps an episode reached after that:

- Claude Code pins `claude_code_version: "2.1.108"`, which sandbox
  sessions require.
- Each profile declares `sandbox_config` with a mandatory image, so a
  missing image fails at resolve and the image can be set under the
  composed agent's name. All but Hermes set `ttl_s: 14400`, without
  which OpenSandbox ends the sandbox after 10 minutes; Hermes derives
  its TTL from its own timeouts.
- `head_server.host` stays on 127.0.0.1. `use_absolute_ip` otherwise
  puts the head server, whose config endpoint is unauthenticated, on the
  address sandboxes reach.

A new test composes each profile onto HLE, seeds the composed agent with
the request HLE's Environment Server builds, and checks that the seed
reaches sandbox creation with the setting and is refused without it.

Signed-off-by: gwarmstrong <[email protected]>

* fix(configs): grant no tools from judge servers that serve none

equivalence_llm_judge, math_with_judge and mcqa register no tool routes, but
their Environment Servers granted the agent their Resources server over
direct_http, a leftover of NVIDIA-NeMo#4953's switch from the legacy_agent relay. Every
config of these servers binds simple_agent, which accepts a seed with no
grant, so dropping the transport changes nothing for it. A session harness,
which rejects a required direct_http grant, now runs HLE, HLE Diamond, GPQA
and APEX Shortlist without a per-benchmark override.

The adapter READMEs and profile comments drop that override. The profile
test now seeds each composed agent through HLE as shipped, and keeps a case
that grants direct_http to show the 422 still guards pairings whose
Resources server serves tools.

Signed-off-by: gwarmstrong <[email protected]>

* test(agents): seed each profile in its adapter's own suite

The core test that seeded each composed agent imported all six adapters,
so core coverage measured their modules, about 6,700 statements that
only the adapters' own suites exercise, and fell to 87.57%, under its 95%
floor. The seed check now lives in tests/session_harness_profiles.py and
runs from a test in each adapter's suite, in that adapter's environment,
which also runs the Hermes case that the core venv had to skip. The core
test keeps the config-only checks.

Signed-off-by: gwarmstrong <[email protected]>

* fix(claude-code): keep extra_env from re-enabling background tasks

Signed-off-by: gwarmstrong <[email protected]>

* fix(agents): keep the profiles' agent server off the sandbox network

use_absolute_ip gave the agent server the address sandboxes reach. An
unseeded request to its /v1/responses runs the harness on the Gym host
with its built-in tools, so a sandbox could start one there. Each profile
now binds its agent to 127.0.0.1, like the head server; only the model
server, which the sandboxes need, takes the reachable address. No
adapter's sandbox calls its own agent server.

Signed-off-by: gwarmstrong <[email protected]>

* fix(agents): refuse an unenforceable sandbox network with a 422

restrict_sandbox_network raised ValueError when a restricted
network_access could not be enforced: an explicit provider network
policy as well, a provider without network policies, or an endpoint
the sandbox cannot reach. The seed route answered it with a 500, which
the Environment Server retries, though no attempt can fix the
configuration. The helper now raises AgentSeedRejectedError, still a
ValueError, so every adapter that calls it refuses the seed once with
HTTP 422, before any sandbox is created.

Pi also built its tool egress from every MCP grant, including an
optional one it leaves out at activation, so such a grant at a loopback
URL failed the seed. Egress now covers only the grants Pi keeps.

Signed-off-by: gwarmstrong <[email protected]>

* test(opencode): check that an unenforceable network_access is refused with a 422

With NVIDIA-NeMo#5554's restrict_sandbox_network change, a restricted network_access the provider cannot enforce (here an explicit network_policy as well) refuses the seed with HTTP 422 before any sandbox is created, instead of a retried 500.

Signed-off-by: gwarmstrong <[email protected]>

* docs(agents): tell harness authors to restrict an owned sandbox's egress

The Add or Update a Harness page and the add-harness skill now say that an
adapter that creates its own sandbox exposes network_access and passes the
spec through restrict_sandbox_network, that settings it cannot enforce are
refused with AgentSeedRejectedError, and that a restricted sandbox gets its
runtime by upload or from a preinstalled sandbox_runtime_dir. They also list
the tests, the model_only pairing run, and an egress exit check, so a new
harness cannot leave a sandbox with open egress on a benchmark graded on the
model's own knowledge.

Signed-off-by: gwarmstrong <[email protected]>

* fix(pi): refuse unusable network and runtime settings with a 422

Addresses the review of the Pi egress change:

- A borrowed session with a restricted network_access, and a preinstalled
  runtime that is missing or runs another version, raise
  AgentSeedRejectedError: a final, logged 422 instead of a retried 500. A
  runtime check that hits a transport error or timeout stays retryable.
- A test covers the MCP-only filter on tool egress: an optional
  direct_http grant opens no host.
- The Pi README describes the runtime directory as copied whole (with
  libstdcpp/ on older Alpine), says a restricted sandbox needs it or a
  prebaked default path, recommends absolute_ip_server_types so only the
  model server leaves loopback, and notes that full isolation needs the
  OpenSandbox dns+nft egress mode.
- The harness guide lists agents/utils/sandbox_network.py and the egress
  notes, and the OpenSandbox page points at restrict_sandbox_network.

Signed-off-by: gwarmstrong <[email protected]>

* feat(pi): restrict the benchmark profile's sandbox to the model server

Addresses the second review of the Pi egress change:

- Pi's benchmark profile sets network_access: model_only, like
  pi_sandboxed_agent's profile, so an HLE or GPQA run that uses it as
  shipped no longer gets open internet. A search preset overrides it with
  model_and_tools. sandbox_runtime_dir is required (???), because a
  restricted sandbox cannot download Pi; null keeps an image prebaked at
  the default path.
- restrict_sandbox_network takes the provider instead of its name, so the
  move to SandboxSpec.egress_rules and provider capabilities (NVIDIA-NeMo#5363) only
  changes the helper's body, not its callers.
- The README says a borrowed sandbox relies on its owner's policy.

Signed-off-by: gwarmstrong <[email protected]>

* test(agents): read each profile's network settings from its own file

The profile tests derive which profiles restrict egress and require a runtime directory from the profiles themselves, so a harness that restricts its profile changes only its own files and the stacked PRs do not conflict.

Signed-off-by: gwarmstrong <[email protected]>

* fix(opencode): align network refusals and the helper call with the reviewed Pi change

restrict_sandbox_network now takes the provider, and a borrowed session with a
restricted network_access is refused with AgentSeedRejectedError, so the 422 is
logged like the other adapters'. OpenCode writes every MCP grant into its config,
so its tool egress already matches the grants it keeps. The README notes that a
borrowed sandbox relies on its owner's network policy. The benchmark profile
keeps inherit: OpenCode installs its runtime from GitHub unless the image
supplies sandbox_executable_path and sandbox_executable_sha256.

Signed-off-by: gwarmstrong <[email protected]>

* test(agents): pin each restricted profile in its adapter's own test

Reading the restricted profiles from the files keeps the stacked PRs apart but cannot catch a profile losing model_only. Pi's own seed-test file now expects model_only and a required runtime directory, so removing either fails it, and the shared helper supplies any harness setting a profile requires (a runtime directory, or a baked binary and its checksum) and checks that each one fails at resolve when unset.

Signed-off-by: gwarmstrong <[email protected]>

* feat(opencode): restrict the benchmark profile's sandbox to the model server

The profile sets network_access: model_only, as the reviewed Pi change does, and requires sandbox_executable_path and sandbox_executable_sha256, because a restricted sandbox cannot download OpenCode. Its own test expects model_only and the required binary, so removing either fails it.

Signed-off-by: gwarmstrong <[email protected]>

* fix(agents): refuse a required tool grant that model_only would block

Addresses Yu Yao's review of the Pi egress change:

- restrict_sandbox_network takes the required tool grants and refuses them
  under model_only with AgentSeedRejectedError. The policy blocks their
  hosts, so a session would otherwise fail only after the sandbox and the
  runtime exist, as a retried 5xx. Pi passes its required MCP grants.
- A host written with a trailing dot no longer yields a rule the egress
  sidecar never matches, and provider_options: null is restricted like an
  empty mapping instead of raising a 500.
- Pi's tests cover both restricted values for a borrowed sandbox, a model
  URL that fails to resolve (the provider is closed), and a preinstalled
  runtime that exits nonzero or reports a version prefix.
- The profile comment says that with sandbox_runtime_dir: null the image
  must hold the runtime at the default path with its ready marker.

Signed-off-by: gwarmstrong <[email protected]>

* docs(pi): say which grants a restricted seed refuses

Under model_and_tools, a grant at an unreachable address refuses the seed even when optional, and model_only refuses a required grant.

Signed-off-by: gwarmstrong <[email protected]>

* fix(opencode): refuse a required tool grant that model_only would block

Addresses Yu Yao's review:

- OpenCode passes its required MCP grants to restrict_sandbox_network, so
  under model_only a required grant is refused at seed with a 422 instead
  of failing after the sandbox exists.
- The README and the network_access description say that a restricted
  sandbox needs sandbox_executable_path (or the runtime at the cache path)
  and ripgrep in the image, which grants a restricted seed refuses, and
  that full isolation needs OpenSandbox's dns+nft egress mode.
- The egress test uses a required and an optional MCP grant on different
  hosts plus a direct_http grant that must stay out of the policy, the
  borrowed refusal covers both restricted values, and a route test covers
  the required-grant refusal.

Signed-off-by: gwarmstrong <[email protected]>

* feat(hle_diamond): run the text tool presets as opencode_agent and pi_agent sessions

The opencode, opencode_search, opencode_reference, pi and pi_search presets
leave the legacy_agent relay and the deprecated sandboxed agents. They run
as opencode_agent / pi_agent sessions through each agent's benchmark
profile, driven by the benchmark's own single_agent_turn_legacy
Environment Server. The judge binding and routing name are unchanged.

Each session starts its own sandbox with network_access model_only or
model_and_tools. Such a sandbox cannot download a runtime, so OpenCode runs
the science image's preinstalled binary at the digest its Dockerfile checks,
and Pi runs the Pi image's /opt runtime. Search presets list Tavily in the
agent's tool_servers. Reasoning stays high: OpenCode sets reasoning_effort,
Pi sets thinking high plus provider_compat.supportsReasoningEffort, so Pi
requests now carry reasoning_effort. The environment note moves to
system_prompt, because a session's opencode_config takes only permission
and tools.

opencode_full and opencode_search_full stay on opencode_sandboxed_agent
behind the relay, since sessions take text input only. Their agent is
renamed hle_diamond_opencode_full_agent so sandbox_docker_local.yaml can
override both kinds of agent. README and tests are updated; the relay
switch test drops the four hle_diamond rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* fix(hle_diamond): grade failed session runs and document offline OpenCode limits

The relay presets set execution_failure_reward_zero, so a harness crash,
nonzero exit or deadline became a reward-0 row in the mean. The session
agents default verify_after_agent_error to false, so such a run became a
failure row outside the denominator. opencode, opencode_reference and pi
(and the search presets that compose them) now set it to true, and the
session preset tests check it.

The README now notes that OpenCode stalls about 70 s per start offline
while it tries to install @opencode-ai/plugin (neither science image ships
the plugin dependency bundle), that session presets use opencode_agent's
default permissions instead of '*': allow, and that the harness
transcript under the artifacts directory exists only for the full presets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* chore(hle_diamond): mark the public OpenCode runtime digest for the secrets detector

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* fix(hle_diamond): outlast the seed with the sandbox TTL and record the OpenCode tool-switch blocker

- Session presets set sandbox_config.ttl_s to 16200. The profile's 14,400 s TTL starts when the
  seed creates the sandbox, while the 14,400 s run budget starts only after the seed (up to the
  1,200 s ready wait), so a run near its deadline would lose its sandbox and be retried instead
  of graded. The test now requires ttl_s >= timeout + ready_timeout_s.
- README: a probe shows that OpenCode sessions still run webfetch and task subagents although
  the presets turn them off (tools map), and deny rules under permission after "*": allow did
  not stop them either. Recorded as a blocker under Known limitations; the fix belongs in
  opencode_agent.
- README: Pi creates the session sandbox before waiting for a concurrency slot (keep
  --concurrency at or below 512), the full presets' scores come from a different harness, the
  effort-check request counts match the rebuilt smoke, and the Failed runs bullet is rewrapped.
- Test: opencode_search_full keeps the same Tavily server and environment note as
  opencode_search.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* feat(hle,apex_shortlist): run the OpenCode presets through opencode_agent sessions

benchmarks/hle/opencode.yaml, hle/opencode_search.yaml and apex_shortlist/opencode.yaml now run
opencode_agent through each benchmark's single_agent_turn_legacy Environment Server. Each session
creates its own sandbox from the offline science image, reaching only the model server (and the
Tavily server for search, granted through the agent's tool_servers). The shared settings live in
responses_api_agents/opencode_agent/configs/profiles/offline_science.yaml and follow
opencode_sandboxed_agent's benchmark preset where opencode_agent has the setting; the benchmark
READMEs list what differs (output budget, compaction and step limit, failure handling, command
rules, artifacts).

The relay presets are kept as *_legacy_agent.yaml with deprecation notes, and their citations
(the configuration troubleshooting page, the migration script's message and its routing test)
are repointed.

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

* feat(hle,apex_shortlist): run the Pi presets through pi_agent sessions

benchmarks/hle/pi.yaml, hle/pi_search.yaml and apex_shortlist/pi.yaml now run pi_agent through
each benchmark's single_agent_turn_legacy Environment Server. Each session creates its own
sandbox from the Pi offline science image and uses the Pi runtime in it (sandbox_runtime_dir
/opt, pi_version 0.85.1), with the deprecated preset's output policy, compaction setting, Bash
cap and network policy. The shared settings live in
responses_api_agents/pi_agent/configs/profiles/offline_science.yaml; the benchmark READMEs list
what still differs (failure handling, the runtime guard's prompt note, refused request fields,
artifacts).

pi_agent sessions now honor output_token_policy: with remaining_context they load
remaining-context.mjs, which drops each request's output cap, instead of output-limit.mjs. The
setting was applied only to local runs, so a session silently capped every call at
max_output_tokens.

The relay presets are kept as *_legacy_agent.yaml with deprecation notes, and their citations are
repointed.

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

* fix(opencode_agent): mark the pinned OpenCode digest as an allowed hex string

The secrets detector flags the SHA-256 of the image's OpenCode binary in the offline science preset.

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

* fix(pi_agent): run the offline science preset on one worker

pi_agent's module exposes no app for uvicorn's extra workers, so the deprecated preset's four
workers never start ("Attribute app not found"), and its session state is process-local.

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

* fix(hle,apex_shortlist): keep OpenCode session sandboxes to the model server and correct the docs

Scope use_absolute_ip to the model server in the offline science profile, and to the
model and Resources servers in hle/opencode_search, so a sandbox allowed to reach the
model server's host does not also reach the Environment and judge servers bound there.

Docs: list the request fields opencode_agent refuses, scope the shared OpenCode/Pi guide
to the *_legacy_agent presets, update the opencode_agent README for the migrated
presets and the new profile, correct OpenCode's MCP timeout defaults, and point the
Diamond OpenCode header at hle/opencode_legacy_agent.yaml.

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

* fix(hle,apex_shortlist): keep Pi session sandboxes to the model server and correct the Pi docs

Scope use_absolute_ip to the model server in the Pi offline science profile, and to the
model and Resources servers in hle/pi_search. List `instructions` among the request
fields pi_agent accepts, say that auto_compaction and output_token_policy apply to
sessions too (and that remaining_context removes the per-call cap), scope the shared
guide to the Pi *_legacy_agent presets as well, and give the one-worker setting its
real reason (no module-level app) and its 512-session ceiling.

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

* refactor(hle,apex_shortlist): build the OpenCode offline science profile on profiles/benchmark.yaml

The profile repeated the address, head server, provider, network and sandbox-lifetime settings of
profiles/benchmark.yaml. It now composes that profile and keeps only what the offline science presets
add; the resolved HLE, HLE search and APEX Shortlist configs are unchanged. The mcp_tool_timeout_seconds
comment now gives OpenCode's defaults: 30 s to connect and the MCP SDK's 60 s per call.

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

* refactor(hle,apex_shortlist): build the Pi offline science profile on profiles/benchmark.yaml

The profile repeated the address, head server, provider, network and sandbox-lifetime settings of
profiles/benchmark.yaml. It now composes that profile and keeps only what the offline science presets
add; the resolved HLE, HLE search and APEX Shortlist configs are unchanged.

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

* refactor(hle_diamond): keep the relay presets as *_legacy_agent

Follow the naming of the other agent-session migrations: the session
presets keep the plain names, and each relay preset stays selectable
under its name plus _legacy_agent with a deprecation note naming the
preset that replaces it.

- opencode, opencode_search, opencode_reference, pi and pi_search:
  main's relay presets come back as <name>_legacy_agent.yaml, unchanged
  apart from the header and the config_paths between them. They keep
  their agent names, as the hle presets do.
- opencode_full and opencode_search_full become *_legacy_agent: agent
  sessions take text only, so no session preset covers the full set.
- sandbox_docker_local.yaml documents that it does not compose with the
  text *_legacy_agent presets; a test holds the almost-server error.
- The relay-switch test cites the hle_diamond *_legacy_agent presets
  again, with the agent-name rule of the hle migration.
- README, docstrings and tests use the new names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* fix(hle,apex_shortlist): keep OpenCode session sandboxes through the seed and the full run

The 14,400 s TTL from profiles/benchmark.yaml starts when the seed creates
the sandbox, but the 14,400 s run budget only after the seed, which waits
up to 1,200 s for readiness. A run near its deadline would outlive its
sandbox, and a lost sandbox is retried, not graded. Set the TTL to the run
budget plus 1,800 s, as HLE Diamond's session presets do.

Add a test that composes the three presets as gym eval loads them and
checks the routing, the addresses, the subagent denial, and that the TTL
covers the readiness wait plus the run budget.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* fix(hle,apex_shortlist): keep Pi session sandboxes through the seed and the full run

The 14,400 s TTL from profiles/benchmark.yaml starts when the seed creates
the sandbox, but the 14,400 s run budget only after the seed, which waits
up to 1,200 s for readiness. A run near its deadline would outlive its
sandbox, and a lost sandbox is retried, not graded. Set the TTL to the run
budget plus 1,800 s, as for OpenCode.

Add a test that composes the three presets as gym eval loads them and
checks the routing, the addresses, the Pi version, the output token
policy, and that the TTL covers the readiness wait plus the run budget.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* test(pi_agent): scope the loopback note in the offline science preset test

hle/pi_search sets absolute_ip_server_types to include resources_servers
so the sandbox can reach Tavily, which also moves the HLE judge off
loopback. The comment said the judge stays on loopback in every case;
say that it does except in the search preset.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* feat(hle_diamond): run the text tool presets as opencode_agent and pi_agent sessions

Port of NVIDIA-NeMo#5702's own changes onto NVIDIA-NeMo#5826, without the NVIDIA-NeMo#5458 merge: the five text session presets
(opencode, opencode_search, opencode_reference, pi, pi_search), the relay presets kept as
*_legacy_agent, the local Docker override, the README and the tests. The relay-switch test rows for
hle_diamond move to the *_legacy_agent names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* refactor(hle_diamond): compose the offline science profiles instead of NVIDIA-NeMo#5458's opt-ins

The session presets now compose responses_api_agents/{opencode,pi}_agent/configs/profiles/offline_science.yaml,
as benchmarks/hle does, and add only the HLE-Diamond judge and dataset; a test holds the agents equal to hle's
apart from those two keys. The search presets let the Resources servers leave loopback and give OpenCode's MCP
calls 300 s, as hle's do.

Dropped, because only NVIDIA-NeMo#5458 defines them: verify_after_agent_error, OpenCode reasoning_effort,
output_token_policy and declare_model_limits, and Pi provider_compat (with `thinking`, which never left the
sandbox without it). OpenCode now asks for 32,768 output tokens per call within a 229,376-token context, as on
hle; a harness crash is retried, then reported as a failed rollout. "Reasoning high" goes on the model server's
extra_body (++policy_model.responses_api_models.<type>.extra_body.reasoning_effort=high), which the README
documents and the Quickstart commands use; the session agents refuse a request `reasoning` field.

The README also records the OpenCode tool probe (webfetch, websearch, task and skill are no longer offered) and
drops "agent sessions take text input only".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* fix(hle_diamond): address review: per-preset effort keys, step-cap wording, config tests

- README: the OpenCode relay presets' effort override names each preset's agent instance
  (hle_diamond_opencode_full_agent, hle_diamond_opencode_reference_agent, hle_diamond_opencode_agent);
  under any other name the override adds an unused agent block and the effort stays high.
- README: the step cap and compaction setting are left unset by the shared offline_science
  profile, not missing from opencode_agent; give the per-run overrides that restore them.
- Headers of the full relay presets name opencode_legacy_agent.yaml and
  opencode_search_legacy_agent.yaml, whose settings they share, instead of the session presets.
- test_hle_diamond.py: drop the tests and asserts that restate preset values (relay wiring, header
  text, the full presets' effort knob, timeout, notes, egress and tool servers per preset,
  config_paths, sandbox_runtime_dir) and compare the Docker override's kept settings with the
  preset itself instead of literals. The routing, schema, hle-equality, image-pin, TTL, deny-order,
  Docker-override refusal and drift checks stay.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* docs(hle_diamond): correct the crash-grading and activation-wait notes

A harness crash reaches the Environment Server as a failed agent call, which it
turns into a dependency failure before agent_outcome_policy runs, so no
by_failure_kind setting can grade it; drop the `unknown: verify` workaround.
OpenCode, like Pi, starts a first activation's budget only once it holds a
slot, so its queue wait also runs outside the budget while the sandbox idles.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

* refactor(hle_diamond): keep the full presets' names, mark the full-set prepare script legacy

Review: opencode_full.yaml and opencode_search_full.yaml keep their names (they
still run opencode_sandboxed_agent behind the relay); only their agent instance
stays renamed. prepare_opencode.py becomes prepare_opencode_legacy.py, since only
those two relay presets use it. The prepare.py and prepare_text.py docstrings now
say the session presets use prepare_text.py, and the README names the two full
presets wherever it describes the relay presets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: weijia chen <[email protected]>

---------

Signed-off-by: gwarmstrong <[email protected]>
Signed-off-by: weijia chen <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Co-authored-by: gwarmstrong <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: yaoyu-33 <[email protected]>

This branch was previously deployed

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

Labels

ready-to-merge PR is approved, current, and waiting for final CI or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants