Skip to content

feat(swe): block egress from the agent's sandbox in the SWE servers - #6177

Merged
yaoyu-33 merged 3 commits into
mainfrom
ananthsub/swe-agent-no-network
Nov 16, 2026
Merged

yaoyu-33 merged 3 commits into
mainfrom
ananthsub/swe-agent-no-network

Conversation

@ananthsub

@ananthsub ananthsub commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Adds the agent egress block that deepswe already has, under the same config keys, to seven SWE resources servers: swe_rebench, swe_internal_v1, swemer_v1, swemer_v2, swemer_oml, scale_swe and swe_next.

  • enforce_agent_no_network (default false): when on, the sandbox the server creates for the agent gets a deny-by-default network policy.
  • sandbox_model_server: the model server whose host the policy allows, on every port, so the agent can still reach the model.

The fields and rules live in one config mixin, AgentNetworkConfig, in resources_servers/swebench/agent_network.py. Each server switches its config base class and calls the mixin at startup and when it builds the sandbox spec. The mixin follows the rules core LentSandboxes applies to a lent sandbox:

  • The config refuses the flag without sandbox_model_server, or alongside a network_policy in sandbox_config.provider_options.
  • Startup refuses a sandbox provider that cannot enforce network policies.
  • A model server on a host the sandbox cannot reach refuses the seed with ResourcesSeedRejectedError (HTTP 422), so it fails once instead of being retried.

Only the agent's sandbox is restricted. Evaluation sandboxes keep their network, because grading installs test dependencies. swe_rebench, swe_internal_v1 and the swemer servers already create the agent's sandbox for a session and evaluation sandboxes for a verifier session, so the block applies to the session's sandbox. scale_swe and swe_next have no such marker, so their _create_sandbox takes a keyword-only for_agent flag that seeding sets.

Not covered: swemer_ultra, swe_gym, r2e_gym and denovo_swe also seed an agent sandbox, and this change does not touch them.

Why

With open egress, RL agents learn to fetch the task's upstream fix: newer package releases, or the fixed source from GitHub, through any language runtime. A command deny-list cannot stop that. These servers create the agent's sandbox in seed_session and lend it to the agent, so the agent's own network_access setting cannot put a policy on it.

No issue is linked. The field names match deepswe's, so recipes that already set them for deepswe work unchanged here.

Turning it on

The setting is off by default, so existing configs behave as before. Both keys are listed in each server's YAML config. A recipe that turns it on needs:

  • an OpenSandbox provider;
  • sandbox_model_server naming the same server as the agent's model_server, advertising a host the sandbox can reach (use_absolute_ip=true);
  • an agent that needs nothing else from the network. Both OpenCode agents download OpenCode inside the sandbox by default, which the block stops. Use a preinstalled or uploaded binary instead: preinstalled_opencode or the remote_opencode_* settings for opencode_sandboxed_agent, the preinstalled binary and its SHA-256 for opencode_agent. Without ripgrep in the image, OpenCode's grep and glob tools stop working, but the rollout still runs;
  • the agent's own network_access left at inherit. Both OpenCode agents refuse any other value on a lent sandbox.

Tests

Each of the seven servers has a test module that builds the real server with a recording sandbox and checks that:

  • nothing changes when the setting is off;
  • with the setting on, seeding gives the agent's sandbox a policy that allows only the model server's host;
  • the evaluation sandbox keeps its network;
  • other provider options survive and the shared config is not changed;
  • a model server on a loopback host refuses the seed with HTTP 422;
  • startup refuses a provider without network policies;
  • the config refuses the flag without a model server, or alongside a configured network_policy;
  • both config fields default to off.

The scale_swe session test stubs record which sandboxes were created for the agent, and the full seed-and-verify flow checks that only the task sandbox was. The new tests fail on the base branch. They also fail when seeding stops passing for_agent, when the startup check is removed, and when the seed refusal is not turned into a 422.

Commands run:

PYTHONPATH=$PWD pytest -n 16 resources_servers/{swe_rebench,swe_internal_v1,swemer_v1,swemer_v2,swemer_oml,scale_swe,swe_next}/tests
pre-commit run --files <touched files>

Rollout evidence

Ran locally on a workstation at ee136f4045, driving sandboxes on a remote OpenSandbox deployment. No Slurm job.

Not run: a full OpenCode rollout. OpenCode in the sandbox calls the Gym model server's own address, and a remote sandbox cannot reach a server on the workstation. That is true with the flag off as well, so this setup cannot finish an OpenCode rollout either way. The checks below exercise each part of the change on real sandboxes instead.

Waiting: the OpenCode rollout with the flag on, on a Slurm CPU node. Gym runs on the cluster node, which the sandbox can reach, but our OpenSandbox deployment has no OpenCode mount, so with egress blocked the sandbox cannot install OpenCode. That run waits on #6232, which uploads a pinned local OpenCode binary.

Egress from the agent's sandbox. A small driver built each server's real config and server object, and created the agent's sandbox and an evaluation sandbox through the server's own _create_sandbox. The policy model server was set to advertise inference-api.nvidia.com. It then ran curl inside each sandbox:

Server, flag Sandbox Model host pypi.org github.com
swe_rebench, on agent HTTP 401 (reached) blocked: cannot resolve host blocked: cannot resolve host
swe_rebench, on evaluation HTTP 401 HTTP 200 HTTP 200
swemer_v1, on agent HTTP 401 (reached) blocked: cannot resolve host blocked: cannot resolve host
swemer_v1, on evaluation HTTP 401 HTTP 200 HTTP 200
scale_swe, on agent HTTP 401 (reached) blocked: cannot resolve host blocked: cannot resolve host
scale_swe, on evaluation HTTP 401 HTTP 200 HTTP 200
swe_rebench, off agent HTTP 401 HTTP 200 HTTP 200
swe_rebench, off evaluation HTTP 401 HTTP 200 HTTP 200

The policy on each flag-on agent sandbox was {"defaultAction": "deny", "egress": [{"action": "allow", "target": "inference-api.nvidia.com"}]}. The 401 is the inference API answering an unauthenticated request, so the allowed host is reachable through the policy. The probe sent no key into the sandbox.

Grading with the flag on. gym env start ran the swe_rebench servers with the flag on and sandbox_model_server set to an openai_model policy server. apply_golden_patch.py then graded two example rows, intel__rohd-458 and syuilo__aiscript-257. Both scored reward 1.0, with the patch applied and evaluation completed, so the evaluation sandbox still installs and grades.

Startup refusal. gym env start for swe_rebench with the flag on and no sandbox_model_server stops at startup with "enforce_agent_no_network needs sandbox_model_server, the model server the agent calls".

With open egress, RL agents learn to fetch the task's upstream fix: newer
package releases, or the fixed source from GitHub, through any runtime.
swe_rebench, swemer_v1, swemer_v2, swemer_oml, scale_swe and swe_next
create the agent's sandbox in seed_session and hand it to the agent, so
the agent's own network_access cannot put a policy on it.

Add enforce_agent_no_network and sandbox_model_server to these servers.
When enabled, the agent's sandbox gets a deny-by-default policy that
allows only the model server's host. It fails closed for a provider
without network-policy support or a model server that advertises a
loopback host. Evaluation sandboxes keep their network. The setting is
off by default.

The servers with episode sessions treat the sandbox created for a
session as the agent's; scale_swe and swe_next mark it with for_agent.
The shared policy builder lives in resources_servers/swebench.

Co-authored-by: Jiaqi Zeng <[email protected]>
Signed-off-by: Ananth Subramaniam <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

Move enforce_agent_no_network and sandbox_model_server into one config
mixin, AgentNetworkConfig, in resources_servers/swebench/agent_network.py,
and follow the rules LentSandboxes applies to a lent sandbox:

- the config refuses the flag without sandbox_model_server, or alongside
  a network_policy in sandbox_config.provider_options;
- startup refuses a provider that cannot enforce network policies;
- a model server the sandbox cannot reach refuses the seed with
  ResourcesSeedRejectedError (HTTP 422), so it fails once instead of
  being retried.

Add swe_internal_v1, which seeds the agent's sandbox the same way as
swe_rebench. Each server now switches its config base class and calls the
mixin at startup and when it builds the sandbox spec. List both keys in
each server's YAML config.

Tests now build the real servers: seeding gives the agent's sandbox the
block, the evaluation sandbox keeps its network, and the config, startup
and seed refusals hold. The scale_swe session test records which
sandboxes were created for the agent.

Co-authored-by: Jiaqi Zeng <[email protected]>
Signed-off-by: Ananth Subramaniam <[email protected]>

@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

RISK: Complete a representative model-driven rollout

The PR explicitly reports no full OpenCode rollout. The real-sandbox egress probes and two successful golden-patch grades are useful evidence, but they do not exercise runtime setup, inference through the advertised Gym model endpoint, and verification together. AGENTS.md requires representative real smoke rollouts for behavior-changing environment work.

Could you run one supported pairing end to end on the latest commit, using a sandbox-reachable Gym model server and an offline-ready OpenCode runtime? Keep the agent's network_access at inherit; do not broaden the allowlist to make installation succeed. Record the command, task, model, rollout artifact and inspected verifier outcome. Acceptance should show that the agent reaches the Gym model endpoint, external hostname and literal-IP requests are blocked, and grading completes in a separate sandbox with its original network settings. Retain the reported golden-patch checks and confirm that the same pairing still runs with enforcement disabled. No reward-distribution comparison is requested because this PR does not change the verifier's scoring logic.

NOTE: Document the new SWE configuration in the shipped guide

Suggestion: add a short section to the existing OpenSandbox egress guide. The new YAML entries expose the switch, but neither those entries nor the existing guide explains how to configure these seven servers. The operational requirements currently live in the PR description and the config mixin's docstring.

Include one complete resources-server overlay with a structured sandbox_model_server reference matching the agent's model, the offline-runtime requirement, and the dns+nft deployment prerequisite. Keep the distinctions explicit: enforcement defaults off, only agent sandboxes receive the injected policy, and the allowed host is reachable on every port. Acceptance is a documented example that resolves against a shipped pairing and describes both restricted agent execution and unrestricted grading without suggesting that DNS-only filtering provides full isolation.

I completed static inspection of all 23 changed files and their directly affected seed, policy and verification paths. I did not execute tests or rollouts. The inline RISK identifies a source-evidenced import-contract regression.

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

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the feature New capabilities, enhancements, or enablement work label Nov 16, 2026
@copy-pr-bot

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

@yaoyu-33

Copy link
Copy Markdown
Contributor

/ok to test 0f84c2c

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

Reviewed 0f84c2c: the seven SWE servers apply the opt-in policy to agent sandboxes while leaving verification sandboxes unrestricted; invalid provider/model configurations fail closed, and the public-import regression is fixed. No additional blocking implementation issue found in this static review.

Validation limits: I did not run tests or model rollouts for this review, and this pass was not independently checked. CI is still running. The author's real-sandbox egress probes and golden-patch grading are useful evidence, but the full model-driven OpenCode smoke remains outstanding as documented in the PR. This approval does not certify that validation as complete.

@yaoyu-33 yaoyu-33 added the ready-to-merge PR is approved, current, and waiting for final CI or merge label Nov 16, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers label Nov 16, 2026
@yaoyu-33
yaoyu-33 added this pull request to the merge queue Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

Merged via the queue into main with commit 2831db3 Nov 16, 2026
62 checks passed
@yaoyu-33
yaoyu-33 deleted the ananthsub/swe-agent-no-network branch November 16, 2026 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers feature New capabilities, enhancements, or enablement work 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.

3 participants