Repository navigation
feat(hermes): restrict the egress of agent-created sandboxes - #5558
Conversation
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]>
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]>
|
/ok to test 7967278 |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP WITH CARE
Two RISK findings remain: deterministic network-configuration errors return retryable 500s, and the supplied rollout evidence doesn't cover the Pi changes. I found no BLOCKERs.
RISK — Include representative Pi smoke-rollout evidence
The supplied rollout results cover Hermes, but this changeset also adds Pi egress restrictions and preinstalled-runtime setup in Pi's seed path. The repository quality bar requires representative real smoke rollouts for behavior-changing agent work. Unit tests and Hermes results don't establish that Pi's new setup and activation paths work together.
Could you include Pi results, or link the evidence from the stacked PR if it already exists? No code change is implied by this finding. The evidence should show an agent-created OpenSandbox sandbox using the documented preinstalled runtime: model_only seeds without downloading the runtime, completes a model turn, reaches verification, and closes successfully; model_and_tools additionally completes a granted MCP call while unrelated egress remains blocked. Retain inherit behavior and borrowed-sandbox rejection. These are proposed acceptance checks, not executed results. This is an evidence gap, not a demonstrated runtime failure.
I inspected all nine changed files and their directly affected policy, runtime, cleanup, and HTTP-error paths. I checked the shared-policy topic directly because its delegated report wasn't returned. This review was source-only; I couldn't execute tests or independently verify the reported remote rollouts.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
| str(access.connection.url) for access in tool_accesses if isinstance(access, MCPToolAccess) | ||
| ], | ||
| ) | ||
| except BaseException: |
There was a problem hiding this comment.
RISK — Return terminal seed refusals for invalid network configuration.
With a reachable model URL, network_access: model_only, and sandbox_config.provider_options.network_policy: {}, the shared helper raises ValueError. This branch closes the provider and rethrows it; Hermes does the same. The ordinary exception becomes HTTP 500 through the agent boundary and failure reply. The Environment Server therefore classifies it as retryable, although another attempt cannot fix the configuration. Restricted access on an unsupported provider follows the same path. This affects invalid restricted-network sessions, not ordinary inherit sessions.
Could you translate validation failures from restrict_sandbox_network into AgentSeedRejectedError in both adapters, as the seed contract specifies? For Pi, add its public import and insert this branch immediately before the current except BaseException:
except ValueError as error:
await provider.aclose()
raise AgentSeedRejectedError(str(error)) from errorFor Hermes, wrap only the helper call in an equivalent except ValueError that raises AgentSeedRejectedError; leave its existing outer handler responsible for closing the provider. Don't translate errors from sandbox.start or other provider operations. The invariant is that deterministic policy refusals return 422 without creating a sandbox, while cancellation and infrastructure errors retain their existing cleanup and failure behavior.
Proposed acceptance checks: call each seed HTTP endpoint with exception middleware installed. The conflicting-policy example and model_only on Docker should return 422 with the specific explanation, close the provider, create no sandbox, and bind no session. Update Pi's conflict test to check the terminal refusal rather than only ValueError. Preserve both adapters' concrete model-only/model-and-tools allowlists, successful valid OpenSandbox seeds, inherit with an explicit provider policy, and borrowed non-inherit rejection. An unexpected error from sandbox creation must still surface as an infrastructure failure. The suggested changes and checks are based on source inspection, not execution.
There was a problem hiding this comment.
Done in #5554's 8a32f14 (merged into this PR in 88122e7; the Hermes test is 87f2230). Rather than catching ValueError in each adapter, restrict_sandbox_network now raises AgentSeedRejectedError for every refusal: an explicit provider network_policy as well, a provider without network policies, or an endpoint the sandbox cannot reach. It is still a ValueError. Pi, Hermes and the other four adapters already close the provider and re-raise from that call unchanged, so each now answers the seed with a 422 before creating a sandbox. Errors from sandbox.start and other provider operations are untouched. Pi's conflict test now posts the seed over HTTP for the conflicting-policy and Docker cases and checks the 422, the provider close, no sandbox and no bound session. Hermes and the other adapters each have the same 422 check, and the helper's unit tests assert the 422 for all three refusal kinds.
There was a problem hiding this comment.
Checked: the refusals the helper raises (an explicit policy, a provider without network policies, a loopback tool URL) are final 422s through /v1/agent_sessions, with the provider closed. One case still returns a retried 500: a loopback model URL, which assert_model_url_reachable_from_sandbox rejects before the helper runs (see my comment on app.py:523).
There was a problem hiding this comment.
Covered here: the loopback model URL case is now a 422 in Hermes (bf1a57d); see the reply on app.py:523.
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]>
… egress change Signed-off-by: gwarmstrong <[email protected]>
…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]>
|
On the Pi smoke-evidence finding: the Pi changes in this diff are #5554's, which this PR is stacked on, and their rollout evidence is in #5554's description (the Rollouts section): #5554. It covers internal HLE runs of Pi on an agent-owned OpenSandbox with the preinstalled runtime ( This PR now also has #5554's review fix merged in (88122e7): |
|
/ok to test 87f2230 |
Both sides added public exports to nemo_gym.agents; both are kept. Signed-off-by: gwarmstrong <[email protected]>
…es egress change Signed-off-by: gwarmstrong <[email protected]>
|
/ok to test d2b334d |
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]>
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]>
Signed-off-by: gwarmstrong <[email protected]>
… 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]> 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.
|
/ok to test bbd90e3 |
Brings in main's latest four commits; this PR's own changes are unchanged. Signed-off-by: gwarmstrong <[email protected]>
|
/ok to test 4f0a029 |
yaoyu-33
left a comment
There was a problem hiding this comment.
Re-reviewed at 4f0a029 (the change is git diff main...head now that #5554 has merged). Everything from my earlier review is addressed, and CI is green on this head.
- A loopback model URL is now a terminal 422 in every mode (
ValueErrorfromassert_model_url_reachable_from_sandboxbecomesAgentSeedRejectedError); required MCP grants are refused undermodel_onlyat seed. - The
network_accessfield description now matches the README: the Agent Server builds and uploads the runtime, so a restricted sandbox needs no network for setup. The README row also has thedns+nftcaveat. - The refusal and borrowed-sandbox tests post to
/v1/agent_sessions, and the egress test uses required, config-declared anddirect_httpgrants and checks the runner's model host against the policy.
Not run here: I did not re-run the suites locally; I read the diff and relied on the green CI at this head.
Non-blocking: the PR body says the stock-image path (runtime uploaded by the Agent Server) has not been run live under model_only; the earlier unit test I ran shows no network command runs during install, so I am not holding on it. Moving the loopback-to-422 conversion into the shared function, for mini-SWE too, can be its own small PR.
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42138948041 |
What does this PR do?
hermes_agentgainsnetwork_access(defaultinherit) for the sandboxes it creates. The value comes from #5554'srestrict_sandbox_network, using the Model Server URL that the adapter already resolves for its reachability check, plus each MCP grant's host formodel_and_tools. A session that borrows a task sandbox rejects any value other thaninheritwithAgentSeedRejectedError. The Agent Server builds Hermes's runtime and uploads it, so a restricted sandbox needs no network for setup. README: the setting.Why. The same reason as #5554, for Hermes: without this, a sandbox Hermes creates has the provider's default network. Stacked on #5554, whose branch this PR targets. Part of #5552.
Validation
gym env test +entrypoint=responses_api_agents/hermes_agent +should_validate_data=true: 353 passed.With the behavior disabled, the new tests fail: model-only and model-and-tools egress, and the borrowed-sandbox rejection. The
inheritcontrol passes.Review follow-up: feat(pi): restrict the egress of agent-created sandboxes #5554's review fix merged in (88122e7), so this adapter's
restrict_sandbox_networkcall refuses an unenforceablenetwork_accesswith a terminal 422.test_unenforceable_network_access_is_a_terminal_seed_refusalchecks the 422, the provider close and that no sandbox is created. Suite in the adapter's own venv: 354 passed.pre-commit run --all-files: clean.Follow-up to the feat(pi): restrict the egress of agent-created sandboxes #5554 review: merged its latest head; the helper call passes the provider; a borrowed sandbox with a restricted value is refused with
AgentSeedRejectedError; the README says a borrowed sandbox relies on its owner's policy. Its benchmark profile setsnetwork_access: model_only; Hermes's runtime is built on the Agent Server and uploaded, so it needs no sandbox network. The adapter's owntest_benchmark_profile.pyexpectsmodel_only(removing it fails the test). Suite: Hermes: 364 passed; profile and helper tests pass.Review follow-up (Yu Yao) at bf1a57d: a loopback model URL is a 422 instead of a retried 500; required MCP grants are refused under
model_only; the field description now matches the README (the runtime is built and uploaded by the Agent Server). Tests go through/v1/agent_sessionsfor each refusal and check the runner's model host is the one the policy allows. Hermes suite with the profile and helper tests: 399 passed.Rollouts
On the internal OpenSandbox deployment used for #5554's egress checks, before this PR's review changes, a sandbox image with Hermes's runtime baked in imported Hermes with egress limited to the model and tool hosts, while
nodejs.org, the npm registry and GitHub's DNS name were blocked. The stock-image path, with the runtime uploaded by the Agent Server, has not been run live undermodel_only.Internal runs on the
georgea/nemo-gymfork at ee833ed, which carries this change before its review updates (Nemotron 3.5 Super on vLLM, 5 text tasks each):model_only: 5/5 rollouts completed, graded and healthy.model_and_toolsand Gym's Tavily server: 5/5 healthy, with the search tools called in 4 of 5.model_only: 5/5 healthy.Compatibility and benchmark impact
Default unchanged (
inherit).The adapter's own default stays
inherit. Its benchmark profile (from #5550) now setsnetwork_access: model_only, so a run that uses the profile gets the restricted sandbox; open-network scores are not comparable.Checklist
pre-commit run --all-files).git commit -s).