Skip to content

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

Merged
gwarmstrong merged 22 commits into
NVIDIA-NeMo:mainfrom
gwarmstrong:georgea/openclaw-agent-egress
Nov 6, 2026
Merged

gwarmstrong merged 22 commits into
NVIDIA-NeMo:mainfrom
gwarmstrong:georgea/openclaw-agent-egress

Conversation

@gwarmstrong

@gwarmstrong gwarmstrong commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Follows #5554, which has merged; this PR now targets main and shows only this harness's changes.

What does this PR do?

  • openclaw_agent gains network_access (default inherit) for the sandboxes it creates. The value comes from feat(pi): restrict the egress of agent-created sandboxes #5554's restrict_sandbox_network, with the Model Server's host and, for model_and_tools, each MCP grant's host. A session that borrows a task sandbox rejects any value other than inherit.
  • openclaw_agent gains sandbox_runtime_dir: an absolute sandbox path that holds a preinstalled runtime in the installer's node/ and openclaw/ layout. Setup checks the version its package declares instead of installing, and a mismatch fails setup.
  • README: both settings.

Why. The same reason as #5554, for OpenClaw. Without this, a sandbox OpenClaw creates has the provider's default network, and a restricted sandbox cannot download OpenClaw. Stacked on #5554, whose branch this PR targets. Part of #5552.

Validation

  • gym env test +entrypoint=responses_api_agents/openclaw_agent +should_validate_data=true: 504 passed, 1 skipped. The skip already existed: it needs a real pinned runtime.

  • With the behavior disabled, the new tests fail. That covers model-only and model-and-tools egress, the borrowed-sandbox rejection, both preinstalled-runtime cases, the absolute-path check, and, separately, the version-mismatch case. The inherit control passes.

  • Review follow-up: feat(pi): restrict the egress of agent-created sandboxes #5554's review fix merged in (7b2089b), so this adapter's restrict_sandbox_network call refuses an unenforceable network_access with a terminal 422. test_unenforceable_network_access_is_a_terminal_seed_refusal checks the 422 and that no sandbox is started. Suite in the adapter's own venv: 505 passed, 1 skipped.

  • 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 sets network_access: model_only and requires sandbox_runtime_dir. The adapter's own test_benchmark_profile.py expects model_only (removing it fails the test). Suite: OpenClaw: 507 passed, 1 skipped; profile and helper tests pass.

  • Review follow-up (Yu Yao) at 83fd017: the preinstalled-runtime check verifies Node 22.19.0+, runs the CLI with a private home, and compares the declared version exactly; a failed check is a 422, a timeout stays retryable; required MCP grants are refused under model_only; README on building sandbox_runtime_dir. Tests: a runtime-check table, the exact check command under a real node, route refusal tests per cause, a configured grant in the egress test. OpenClaw suite with the profile and helper tests: 547 passed, 1 skipped.

Rollouts

On the internal OpenSandbox deployment used for #5554's egress checks, before this PR's review changes, an image with OpenClaw 2026.6.11 preinstalled under /opt/openclaw-runtime reported its version with egress limited to the model and tool hosts, while nodejs.org, the npm registry and GitHub's DNS name were blocked.

Internal runs on the georgea/nemo-gym fork at ee833ed, which carries this change before its review updates (Nemotron 3.5 Super on vLLM, 5 text tasks each, that image):

  • HLE with model_only: 5/5 rollouts completed, graded and healthy.
  • HLE with model_and_tools and Gym's Tavily server: 5/5 healthy, with the search tools called in 3 of 5.
  • HLE Diamond with model_only: 5/5 healthy.

Compatibility and benchmark impact

Defaults unchanged: network_access: inherit and no sandbox_runtime_dir.

The adapter's own default stays inherit. Its benchmark profile (from #5550) now sets network_access: model_only and requires sandbox_runtime_dir, so a run that uses the profile gets the restricted sandbox; open-network scores are not comparable.

Coordination with #5379. #5379 uploads the provider_plugin files right after the installer, and this PR moves the installer into the else: of if sandbox_runtime_dir. Whichever PR merges second must run those uploads after the whole if/else, or a preinstalled runtime skips them; a text merge alone will not catch it.

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. N/A: no new source files.
  • 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]>
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]>
@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 5234a7e

@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 WITH CARE

No code defect found. One required validation-evidence gap remains.

RISK — Supply Pi smoke-rollout evidence for the included changes

The supplied description reports OpenClaw rollouts, but provides no representative Pi rollout evidence for the included network-policy integration and preinstalled-runtime branch. The trusted agent validation requirement calls for real model smoke rollouts when agent behavior changes. OpenClaw results and mocked Pi setup tests don't establish that Pi completes these paths. This is missing evidence, not a demonstrated runtime failure; the uncertainty affects users enabling Pi's new restricted-network/preinstalled-runtime settings.

Correction: Could you link existing Pi results from the preceding PR, or supply representative runs? No code change is requested for this finding.

Acceptance checks: Provide the image, runtime version, relevant configuration and inspected outcomes for:

  • An agent-owned OpenSandbox session with a matching preinstalled Pi runtime, model_only, and no tool grants: model calls succeed, the rollout completes and is graded, and the sandbox is destroyed on close.
  • A model_and_tools session with an MCP grant: the rollout successfully calls the granted tool, is graded, and closes cleanly. Include an egress check showing an unrelated host is blocked.

Preservation: Retain the existing Pi regression assertions: inherit adds no policy; model_only allows only the model host; model_and_tools also allows the grant host; borrowed sandboxes reject restricted modes; explicit policies conflict before creation; matching runtimes skip installation, and mismatched versions fail setup.

I inspected all nine changed files and traced the affected policy, model/tool resolution, runtime execution and cleanup paths. All three delegated inspections reached terminal status; one report wasn't available, so I directly covered its shared-helper, export and test topic. I couldn't execute tests or independently verify the reported rollouts in this read-only review.

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]>
… 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

Copy link
Copy Markdown
Contributor Author

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 (sandbox_runtime_dir: /opt in a baked image): model_only 5/5 completed, graded and healthy, and model_and_tools with Gym's Tavily server 5/5 healthy with the search tools called. It also covers egress probes on the same cell: the model and tool hosts were reachable, while nodejs.org, the npm registry, an inference API and GitHub's DNS name were blocked.

This PR now also has #5554's review fix merged in (7b2089b): restrict_sandbox_network refuses an unenforceable network_access with a terminal 422 instead of a retried 500, and Pi builds tool egress only from the MCP grants it keeps. 61cfd43 adds this adapter's check that an unenforceable network_access is refused with a 422 before any sandbox is created.

@gwarmstrong

Copy link
Copy Markdown
Contributor Author

/ok to test 61cfd43

Both sides added public exports to nemo_gym.agents; both are kept.

Signed-off-by: gwarmstrong <[email protected]>
…claw egress change

The README conflict kept both new paragraphs: network_access, and the benchmark profile from NVIDIA-NeMo#5550.

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

Copy link
Copy Markdown
Contributor Author

/ok to test e041b77

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]>
…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]>

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
gwarmstrong requested a review from a team as a code owner November 5, 2026 22:37
@gwarmstrong
gwarmstrong changed the base branch from georgea/pi-agent-egress to main November 5, 2026 22:37
@gwarmstrong

Copy link
Copy Markdown
Contributor Author

/ok to test 01d0d4f

Brings in main's latest four commits; this PR's own changes are unchanged.

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

Copy link
Copy Markdown
Contributor Author

/ok to test 0c2bcd3

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

Re-reviewed at 0c2bcd3 (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.

  • The preinstalled-runtime check now does the installer's ready path plus the floor: Node 22.19.0 or newer, openclaw.mjs --version runs with a private home, and the declared version matches exactly. error_type stays a retryable RuntimeError; a failed check or another version is a 422.
  • Required MCP grants are refused under model_only at seed instead of after the 120 s probe.
  • A test runs the adapter's exact check command under a real node with a path containing a space, which pins the quoting and the missing trailing newline; the refusal test is parametrized like Pi's. The README covers how to build sandbox_runtime_dir, bash in the image, and dns+nft.

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: under model_only an optional grant is still written into OpenClaw's config and can cost up to 120 s of probe before it is dropped. The README now says so, and dropping it fits the one-restricted-mode follow-up in #5552.

@yaoyu-33 yaoyu-33 added the ready-to-merge PR is approved, current, and waiting for final CI or merge label Nov 6, 2026
@gwarmstrong
gwarmstrong added this pull request to the merge queue Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

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

Merged via the queue into NVIDIA-NeMo:main with commit 957a722 Nov 6, 2026
61 checks passed
@gwarmstrong
gwarmstrong deleted the georgea/openclaw-agent-egress branch November 6, 2026 00:52
d-molinari added a commit that referenced this pull request Nov 8, 2026
…ent wraps

Gym main's #5557 (957a722) wrapped OpenClaw's runtime assignment in parentheses over two lines, so
test_a_harness_image_holds_the_runtime_its_adapter_looks_for[openclaw] no longer found it on #5010 merged into main.
The pattern now allows an opening parenthesis and whitespace before the expression.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
d-molinari added a commit that referenced this pull request Nov 10, 2026
…ent wraps

Gym main's #5557 (957a722) wrapped OpenClaw's runtime assignment in parentheses over two lines, so
test_a_harness_image_holds_the_runtime_its_adapter_looks_for[openclaw] no longer found it on #5010 merged into main.
The pattern now allows an opening parenthesis and whitespace before the expression.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Daniele Molinari <[email protected]>
d-molinari added a commit that referenced this pull request Nov 12, 2026
…ent wraps

Gym main's #5557 (957a722) wrapped OpenClaw's runtime assignment in parentheses over two lines, so
test_a_harness_image_holds_the_runtime_its_adapter_looks_for[openclaw] no longer found it on #5010 merged into main.
The pattern now allows an opening parenthesis and whitespace before the expression.

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

This branch was previously deployed

1 inactive deployment
public — 0c2bcd3c Deployed Nov 5, 2026 by copy-pr-bot[bot] via release / finalize / notify #10547
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 sla:review-overdue Review response is over the one-business-day SLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants