Skip to content

feat(swebench): block agent egress and configure sandbox files and setup - #5656

Closed
bg51717 wants to merge 5 commits into
NVIDIA-NeMo:mainfrom
bg51717:biguo/swe-sandbox-egress-setup
Closed

bg51717 wants to merge 5 commits into
NVIDIA-NeMo:mainfrom
bg51717:biguo/swe-sandbox-egress-setup

Conversation

@bg51717

@bg51717 bg51717 commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Two opt-in sandbox options for the swe_rebench and swe_internal_v1 servers, both off by default:

  • enforce_agent_no_network with sandbox_model_server: the agent's sandbox gets a deny-by-default network policy that allows only the model server's host. With open egress, RL agents learned to fetch the task's upstream fix. Evaluation sandboxes keep their network. A config that cannot work fails at server startup.
  • sandbox_config.files and sandbox_config.setup_command: files uploaded and a command run when the agent's and the evaluation sandbox start, for images that need extra toolchain setup (for example a Maven mirror, or the shipped Chrome wrapper under swebench/toolchain/ so Karma can start Chrome as root).

The setup options are based on Jiaqi Zeng's container setup change (e08656718), made configurable instead of hardcoded.

No separate issue: this PR documents the agent-egress gap and the sandbox setup it addresses.

Proposed labels: feature, area:environment.

Validation

At 7d432ba:

  • gym env test +entrypoint=resources_servers/swe_rebench +should_validate_data=true: 97 passed
  • gym env test +entrypoint=resources_servers/swe_internal_v1 +should_validate_data=true: 69 passed
  • gym env test +entrypoint=resources_servers/swebench +should_validate_data=true: 178 passed
  • pre-commit run --all-files: passed

Rollouts

Smoke run at 7d432ba.

Setup:

  • One 4-GPU node: vllm serve with a Nemotron Nano checkpoint, then gym env start and gym eval run --no-serve, as in tests/e2e/gpu_e2e_test.sh.
  • Configs: swe_rebench_opencode.yaml and swe_internal_v1_opencode.yaml (opencode_sandboxed_agent), opensandbox.yaml, use_absolute_ip: true, sandbox_model_server: policy_model, and OpenCode from remote_opencode_*.
  • Flag on: one rollout per server, an egress probe, and golden-patch grading of one Karma row with the Chrome wrapper set through files and setup_command.
  • Flag off, as the control: the same probe, and the same grading without the wrapper.
  • The probe opens the agent sandbox through seed_session, as the agent does, and runs curl, a DNS lookup and a TCP connect to github.com's IP in it. It does not go through the model, since OpenCode's default permissions refuse fetches to github.com.

Results:

  • Both rollouts finished with their model calls and were graded.
  • Flag on: from each agent sandbox, the model host returns 200 and github.com is unreachable by all three probes. Flag off: github.com returns 200.
  • The Karma row chartjs__chartjs-plugin-zoom-488 resolves on its real image with the wrapper. Its install already adds --no-sandbox, so it also resolves without the wrapper.

Compatibility and benchmark impact

None by default. With enforce_agent_no_network, agents can no longer reach the internet, which can change scores of agents that relied on 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 (so CI unit/server checks pass when applicable).
  • Documentation added or updated, or N/A with justification.
  • Pre-commit checks pass locally (pre-commit run --all-files) (so CI lint/format checks pass).
  • New source files include the required Apache-2.0 SPDX header.
  • All commits have DCO sign-off (git commit -s) (so the DCO check passes).

@copy-pr-bot

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

bg51717 and others added 2 commits November 4, 2026 23:12
With open egress, RL agents learned to fetch the task's upstream fix
(newer package releases, the fixed source from GitHub, through any
runtime). The swe_rebench and swe_internal_v1 servers create the agent's
sandbox in seed_session and hand it to the agent, so the agent's own
network_access cannot apply a policy there and refuses to run.

Add enforce_agent_no_network and sandbox_model_server to both servers.
When enabled, the agent's sandbox gets a deny-by-default policy that
allows only the model server's host; a network_policy already in
sandbox_config.provider_options is kept and extended with that host, as
in deepswe. Evaluation sandboxes never get a network_policy, so they keep
their network. A config that cannot work (no sandbox_model_server, or a
provider without network-policy support) fails at server startup; an
unreachable model server host fails when the sandbox is created.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: bg51717 <[email protected]>
Sandboxes from swe_rebench and swe_internal_v1 only get the toolchain
setup the servers hardcode: swe_rebench writes the Maven mirror into the
evaluation sandbox, and swe_internal_v1 writes none. An image that needs
more (the mirror in the agent's sandbox, a Chrome wrapper so Karma can
start Chrome as root with a small /dev/shm) had no way to get it.

Add two sandbox_config keys to both servers, applied to the agent's and
the evaluation sandbox:

- files: sandbox path -> local source file (relative to the Gym root),
  uploaded at create time. The evaluation's own files win on a shared
  path. A missing source fails at server startup.
- setup_command: run once after the sandbox starts; a non-zero exit
  stops the sandbox and fails the request.

With sandbox_config.env these cover the setup a recipe needs. Ship a
Chrome wrapper under swebench/toolchain/ and document an example in the
swe_rebench README. Defaults are unchanged.

Based on Jiaqi Zeng's container setup change (e086567), made
configurable instead of hardcoded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: bg51717 <[email protected]>
@bg51717
bg51717 force-pushed the biguo/swe-sandbox-egress-setup branch from 3a38093 to 75a9889 Compare November 5, 2026 07:23
@bg51717
bg51717 marked this pull request as ready for review November 5, 2026 07:26
@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Nov 6, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added feature New capabilities, enhancements, or enablement work area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers needs-review PR is ready for code review and waiting on a reviewer labels Nov 7, 2026

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

Thanks for this. Server-side enforcement fills a real gap: a harness's network_access never applies to a task sandbox borrowed from the resources server, so swe_rebench and swe_internal_v1 are the only place to restrict the agent's egress. Using SandboxSpec.files and start_with_setup() for the toolchain setup follows the sandbox rules in AGENTS.md, and a failed setup is stopped and retried as an inconclusive evaluation, as expected.

The points to address are inline. The main one is that a configured network_policy can keep the agent's egress open while the flag is on.

Not covered: we did not run a real OpenSandbox sandbox or a model. The two servers' unit tests pass at this head and when merged onto current main.

For a follow-up rather than this PR: deepswe and swebench_pro each have their own copy of this agent-egress logic, and they disagree on how to combine it with a configured policy. This new helper could become the shared one.

policy = restricted_network_policy(provider_name, [sandbox_server_url(model_server.name, require_reachable=True)])
if configured is None:
return policy
merged = deepcopy(dict(configured))

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.

resources_servers/swebench/agent_network.py:52

When provider_options.network_policy is also configured, this copies it and only appends the model allow rule, so the configured defaultAction survives. A config with defaultAction: allow (or an allow rule for a code host) leaves the agent's egress open while enforce_agent_no_network: true says it is closed, and nothing reports it. Main's agent-side helper refuses this combination instead (sandbox_network.py:45: "Set network_access or sandbox_config.provider_options.network_policy, not both"). Could you either refuse a configured policy at startup when the flag is on, or force deny and add a test with a configured allow policy? For example:

Suggested change
merged = deepcopy(dict(configured))
merged = deepcopy(dict(configured))
# The flag promises deny-by-default, whatever the configured policy said.
merged["defaultAction"] = "deny"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 7d432ba. With enforce_agent_no_network on, both servers now refuse a configured network_policy at startup, as the agent-side helper does; forcing deny alone would keep the configured allow rules. Added startup tests for both servers.

from typing import Any, Mapping, cast

from nemo_gym.config import ModelServerRef
from nemo_gym.sandbox.agent_tools import restricted_network_policy, sandbox_server_url

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.

resources_servers/swebench/agent_network.py:25

nemo_gym.sandbox.agent_tools is a moved path (_moved_paths.py:116): it warns now and is removed in 0.10.0. AGENTS.md asks code outside nemo_gym/ to import from the public API, as swebench_pro does (app.py:38). The tests also patch the old path (swe_rebench/tests/test_app.py:610, swe_internal_v1/tests/test_app.py:375); they should patch nemo_gym.agents.agent_tools.get_server_url.

Suggested change
from nemo_gym.sandbox.agent_tools import restricted_network_policy, sandbox_server_url
from nemo_gym.agents import restricted_network_policy, sandbox_server_url

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 7d432ba. Imports now come from nemo_gym.agents, and both servers' tests patch nemo_gym.agents.agent_tools.get_server_url.

--config responses_api_models/vllm_model/configs/vllm_model.yaml
```

## Sandbox toolchain setup

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.

resources_servers/swe_rebench/README.md:92

Neither README documents enforce_agent_no_network / sandbox_model_server, and a few things about it are easy to trip on:

  • The shipped swe_rebench_opencode.yaml pairing runs OpenCode inside the borrowed task sandbox and, by default, downloads it from opencode.ai (opencode_sandboxed_agent/app.py:1268). With the flag on, that download is denied and every rollout fails at seed, unless preinstalled_opencode or remote_opencode_* is set. MCP tool hosts are blocked too.
  • It needs the OpenSandbox provider and a model host that sandboxes can reach (use_absolute_ip). A loopback host passes the startup check and then fails each seed_session.
  • setup_command also runs in the agent sandbox after egress is restricted, so a step that downloads anything works in evaluation but fails at seed. The Maven/Gradle mirror in the example below is unreachable for the agent too.

Could you add a short section covering these (same in swe_internal_v1/README.md)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 7d432ba. Added an "Agent network restrictions" section to both READMEs covering these points.

),
)
body = app.SWERebenchInstanceRequest(instance_id="o__r-1", repo="o/r", base_commit="abc", image_name="img")
return await app.SWERebenchResourcesServer._create_sandbox(server, body, for_agent=for_agent)

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.

resources_servers/swe_rebench/tests/test_app.py:630

These tests choose for_agent themselves, so the wiring the feature depends on is untested: dropping for_agent=True from seed_session (app.py:302) or passing it from verify (app.py:371) still passes the whole suite (we checked by mutating both). Could you add, for both servers:

  • a test that runs the real seed_session and verify with only AsyncSandbox faked, and asserts that the agent spec has defaultAction: deny and the evaluation spec has no network_policy;
  • a test that builds the server with enforce_agent_no_network: true and no sandbox_model_server, or with a missing files source, and expects the startup error;
  • a failing setup_command: verify returns evaluation_completed=False after retries and stops each sandbox, and seed_session raises without keeping the sandbox.

test_agent_sandbox_gets_the_files_and_setup (:730) also never passes for_agent=True, and only asserts setup is not None.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 7d432ba. Added tests for both servers that go through the real seed_session and verify with only the provider faked: agent and evaluation network policies, startup errors, and setup_command failures (verify retries and stops each sandbox, seed keeps none). Also made setup treat a non-None error_type as a failure.

@@ -0,0 +1,57 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

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.

resources_servers/swebench/agent_network.py:1

A few PR-description asks:

  • Rollouts. This changes agent behavior, and AGENTS.md asks for real smoke rollouts on such changes. Could you share one OpenSandbox run per server with enforce_agent_no_network: true that shows the model calls succeed and an outbound fetch (for example to github.com) is denied, plus one row graded with the toolchain files/setup_command on a real image (for example the Chrome wrapper with Karma)?
  • Issue. Please link an issue, or say why none is needed.
  • Pre-commit. The validation lists pre-commit run --from-ref origin/main --to-ref HEAD, but the checklist ticks --all-files. Which one ran?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated the description at 7d432ba: Rollouts now has the smoke run for both servers, it states why no issue is needed, and pre-commit run --all-files passes.

@github-actions github-actions Bot removed the sla:triage-overdue Review assignment is over the one-business-day SLA label Nov 12, 2026
ananthsub added a commit that referenced this pull request Nov 14, 2026
…rk loans

swe_internal_v1 goes back to its mapping sandbox_config: PRs #5656 and
#6173 read new keys from it with .get(), so it moves to the stage after
they merge. LentSandboxes now refuses network_access no_network, since
the harness in a lent sandbox calls the model server, and
SandboxNetwork's validator returns Self.

Signed-off-by: Ananth Subramaniam <[email protected]>
…ess-setup

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

# Conflicts:
#	resources_servers/swe_internal_v1/app.py
#	resources_servers/swe_rebench/app.py
…no_network

With the flag on, a configured provider_options.network_policy kept its
allow rules for the agent, so both servers now refuse the combination
at startup, as the agent-side helper does. Import the network helpers
from nemo_gym.agents, treat a setup_command error_type as a failure, and
document the agent network restrictions.

Test the wiring through seed_session and verify with only the sandbox
provider faked: the agent and evaluation network policies, files and
setup_command, setup failures and their cleanup, and startup errors.

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

bg51717 commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

Closing this: #6177 and #6173, both now merged into main, add the same agent egress block (same config keys) and the swe_agents container setup to these servers. Recipes that used files/setup_command for that setup can switch to legacy_container_setup: true.

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 needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants