Skip to content

refactor(sandbox): build SWE task sandboxes with the typed SandboxConfig.spec - #6179

Open
ananthsub wants to merge 3 commits into
mainfrom
ananthsub/typed-sandbox-config
Open

ananthsub wants to merge 3 commits into
mainfrom
ananthsub/typed-sandbox-config

Conversation

@ananthsub

@ananthsub ananthsub commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What changed

This PR is the first stage of moving resources servers off hand-built sandbox specs and onto the typed
SandboxConfig.spec(). It changes the shared code and migrates four servers.

Shared code

  • SandboxConfig gains derive_cpu_env (default false). When it is on, spec() adds the CPU-cap environment
    (cpu_cap_env(resources.cpu)) under the config's own env.
  • CpuCappedSandboxConfig is a SandboxConfig whose derive_cpu_env defaults to true. The SWE servers use it
    because they derive the caps by default today. Servers already on SandboxConfig keep the false default, so
    their specs do not change.
  • spec() takes two new keyword arguments:
    • env: the server's own fixed environment. The CPU caps, then sandbox_config.env, override it. That is the
      order these servers apply today.
    • network_policy: the sandbox's egress rule, placed in provider_options["network_policy"]. spec() refuses it
      when provider_options already sets one.
  • SandboxNetwork (new, in nemo_gym.server_runtime) is the single builder of egress rules for sandboxes that a
    resources server starts. It is the private LentSandboxes policy code, made public and typed, with access
    inherit, no_network, model_only or model_and_tools. no_network (deny all egress) is new; deepswe
    needs it, because its agent sandbox denies all egress when no model server is set. A provider without network policies, or an allowed server on a loopback host, is refused as
    ResourcesSeedRejectedError (HTTP 422), as LentSandboxes does today.
  • LentSandboxes builds its egress rule with SandboxNetwork and passes it to spec(). Its constructor and
    behavior are unchanged, and it refuses no_network, because the harness in a lent sandbox calls the model
    server.
  • SandboxSessionResourcesServer reads ttl_s from either a typed SandboxConfig or a mapping, so it serves both
    migrated and unmigrated servers.

Servers migrated

denovo_swe, r2e_gym, swemer_ultra and swe_gym now declare sandbox_config: CpuCappedSandboxConfig and
build their task sandbox with spec(). swemer_ultra passes its Gradle environment and swe_gym its conda
environment as the server env.

#5676 also edits these four app.py files, but only their request classes, so the overlap is textual. No open PR
reads a new sandbox_config key in them. swe_internal_v1 stays on its mapping in this PR, because #5656
(sandbox_config.files) and #6173 (sandbox_config.legacy_container_setup) read new keys from it with .get().
It moves in a later stage, after those PRs merge.

#6177 shares no files with this PR, and none of the four migrated servers is among the seven it changes
(swe_rebench, swe_internal_v1, swemer_v1, swemer_v2, swemer_oml, scale_swe, swe_next). Its
AgentNetworkConfig mixin types sandbox_config as a mapping and reads it with .get(), so this PR leaves those
seven servers alone. Expected order: #6177 lands first, either before or after this PR, then the stage that migrates
its servers.

Why

About 23 resources servers take sandbox_config as an untyped mapping and build SandboxSpec by hand. Most of
these copies are the same 25 lines. Two problems follow:

After this change, a sandbox setting is one spec() argument, and egress rules have one builder.

No issue is linked: this is the structural follow-up to the review of PR #6177.

Later stages

Each later stage is its own PR, with the same spec-equality tests:

  1. After PR feat(swe): block egress from the agent's sandbox in the SWE servers #6177 merges: swemer_v1, swemer_v2, swemer_oml, scale_swe and swe_next. Their
    enforce_agent_no_network and sandbox_model_server keys map onto SandboxNetwork(access="model_only"). A
    recipe that sets the flag without a model server stays refused at load, as feat(swe): block egress from the agent's sandbox in the SWE servers #6177 does. The policy is passed to spec(network_policy=...) for the agent's sandbox only, and
    feat(swe): block egress from the agent's sandbox in the SWE servers #6177's AgentNetworkConfig mixin is retired.
  2. After PRs feat(swebench): block agent egress and configure sandbox files and setup #5656, fix(swe_rebench): pin the upstream log parsers to a commit #6172, feat(swe): opt-in swe_agents container setup for swe_rebench and swe_internal_v1 #6173, fix(terminal_bench_2_1): grade failing pytest runs 0 when test.sh exits before writing reward.txt #6174 and feat(swe): block egress from the agent's sandbox in the SWE servers #6177 merge: swe_internal_v1 and swe_rebench (also moving their
    feat(swe): block egress from the agent's sandbox in the SWE servers #6177 network keys onto SandboxNetwork), each with a
    SandboxConfig subclass for the keys those PRs add (files, legacy_container_setup, and the existing
    use_maven_mirror), plus swebench, terminal_bench_2_1 and opencode_search.
  3. deepswe, deepswe_external1 and swebench_pro, whose network settings map onto SandboxNetwork. deepswe
    then fails closed on providers without network policies; today it runs those sandboxes with open egress.
  4. job_bench, workspace_bench, misalignment_monitor, officeqa and browsecomp_advanced_harness, which read
    the image from the config or pass it straight to SandboxSpec.

spec() will gain a per-task resources argument in the deepswe stage, the first stage that needs it.

Compatibility

  • For the four migrated servers, every sandbox_config key that recipes set keeps its meaning: ttl_s,
    ready_timeout_s, resources, env, metadata, provider_options and derive_cpu_env. The checked-in recipes
    build the same spec as before.
  • A key these servers do not read now fails at startup instead of being ignored. No checked-in recipe sets one.
  • metadata and env values must be strings, as they already are for servers on SandboxConfig.
  • SandboxConfig.derive_cpu_env is a new field with a false default, so existing SandboxConfig users are
    unchanged.

Tests

  • Each migrated server has a test that builds its task sandbox through the real _create_sandbox, using the
    sandbox_config block of its checked-in recipe, and compares the result with the full expected spec: image,
    workdir, TTLs, environment (CPU caps plus the server's own variables), files, metadata, resources and provider
    options. The same test also checks that the config's env still overrides the caps, that derive_cpu_env: false
    still turns them off, and that an unknown key is refused. I wrote these tests before migrating, and the spec tests
    passed against the old code too. The unknown-key test is the only one that fails on the old code, by design.
  • The SandboxNetwork tests cover the server checks for each access level, the deny-all and model-plus-tools rules,
    refusal (HTTP 422) of a provider without network policies or a loopback server, and refusal of a restriction that
    provider_options already sets.
  • The SandboxConfig tests cover the environment layering, derive_cpu_env on and off, and how network_policy
    combines with the other provider options.
  • The LentSandboxes network tests are unchanged apart from the module they patch. A new test checks that
    no_network is refused.
  • r2e_gym and swe_gym each had a test that searched app.py source text for cpu_cap_env(...). The new
    spec-equality test replaces it.

Commands run:

PYTHONPATH=$PWD pytest -n 16 tests/unit_tests resources_servers/{denovo_swe,r2e_gym,swemer_ultra,swe_gym}/tests resources_servers/swebench/tests/test_sandbox_sessions.py resources_servers/{vibench,chartography,gdpval,partner_if,enterpriseops_gym,visual_coding_opencode,gdp_pdf}/tests
pre-commit run --files <touched files>

The unit-suite failures in my local environment are the same set on unmodified upstream/main: they come from
optional packages missing in the local venv, not from this change. gym env test is left to CI.

Rollout evidence

N/A: this changes how specs are built, not the specs themselves. For each migrated server, the tests show that its
checked-in recipe builds the same SandboxSpec as before.

…onfig.spec

SandboxConfig gains derive_cpu_env (default false), and
CpuCappedSandboxConfig defaults it to true for the task sandboxes that
cap tool parallelism today. spec() takes the server's own env, layered
under the CPU caps and the config env, and a network_policy that it
places in provider_options, refusing one that provider_options already
sets.

SandboxNetwork in nemo_gym.server_runtime is the LentSandboxes egress
builder made public and typed, with a new no_network access that denies
all egress. LentSandboxes now builds its rule through it; its behavior
is unchanged.

Signed-off-by: Ananth Subramaniam <[email protected]>
denovo_swe, r2e_gym, swe_internal_v1, swemer_ultra and swe_gym now type
sandbox_config as CpuCappedSandboxConfig and build their task sandbox
through spec() instead of a hand-built SandboxSpec. swemer_ultra passes
its Gradle env and swe_gym its conda env as the server env.

The checked-in recipes build the same spec as before; a sandbox_config
key these servers never read now fails at startup instead of being
dropped. SandboxSessionResourcesServer reads ttl_s from a typed config
or a mapping while the other subclasses still use mappings.

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.

…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]>
@ananthsub
ananthsub marked this pull request as ready for review November 14, 2026 00:43
@ananthsub
ananthsub requested a review from a team as a code owner November 14, 2026 00:43
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 14, 2026 00:43
@github-actions

Copy link
Copy Markdown
Contributor

@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. The four SWE migrations preserve the existing sandbox specs and environment precedence. The shared network-policy extraction and typed/mapping session-TTL handling fit the affected callers.

I reviewed all 24 changed files and their directly affected paths. This was a static review; I couldn't run tests in the read-only environment.

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.

@github-actions github-actions Bot added the sla:review-overdue Review response is over the one-business-day SLA label Nov 16, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added feature New capabilities, enhancements, or enablement work area:sandbox Sandbox providers, isolation, and sandbox runtime contracts needs-review PR is ready for code review and waiting on a reviewer labels Nov 16, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:sandbox Sandbox providers, isolation, and sandbox runtime contracts feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer 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.

2 participants