Skip to content

feat(sandbox): expose the shared OwnedSandboxes owner - #6414

Merged
yaoyu-33 merged 16 commits into
mainfrom
ananthsub/owned-sandboxes
Nov 25, 2026
Merged

yaoyu-33 merged 16 commits into
mainfrom
ananthsub/owned-sandboxes

Conversation

@ananthsub

@ananthsub ananthsub commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Expose nemo_gym.server_runtime.OwnedSandboxes as the shared owner of a server's sandboxes. SimpleServer.sandboxes builds it lazily from the server's provider configuration; .on("provider_field") selects another provider with a separate checkpoint index.

server → OwnedSandboxes → create / lend / stop / checkpoint

The server's lifespan stops remaining owned sandboxes and closes their providers after its own shutdown, within the shared 150-second sweep budget. Checkpoint storage is initialized when configured; an owner that never exports needs no snapshot directory. Secondary provider fields use separate index directories and snapshot-name hashes, including when another server has a similar name. Failed or cancelled provider closes can be retried, and concurrent closes serialize.

The former SandboxSessionCheckpointer name and _checkpoint.sandbox module remain available with deprecation warnings. Invalid provider configuration is refused before a provider is created. No benchmark recipe is migrated in this PR; the SWE-bench checkpoint integration uses the new public name.

Stack

Review bottom to top: #6414 → #6415 → #6416 → #6417. Each PR targets the preceding branch; #6414 targets main. The stack includes main through d80581feb. Follow-up adoption and remaining lifecycle limits are tracked in #6703.

Validation

On the workstation, at 1f7f667ca:

  • pre-commit run --all-files: passed, including import layering and formatting.
  • The following tests: 1286 passed in 39.91s.
pytest tests/unit_tests/server_runtime/test_owned_sandboxes.py tests/unit_tests/server_runtime/test_checkpoint_sandbox.py tests/unit_tests/test_public_api_facades.py tests/unit_tests/test_moved_paths.py resources_servers/swebench/tests/test_sandbox_session_checkpoints.py -n 4 --tb=short --import-mode=importlib

Preparation commits include DCO sign-off. Model rollout: N/A for this shared ownership API and rename; no new agent or verifier policy is adopted. The complete stack also has the real Docker lifecycle smoke recorded in #6417. Cloud-provider lifecycle behavior has not been rerun in this validation.

@copy-pr-bot

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

A client that disconnects cancels its request, and every later await in it.
An unshielded stop in the request's cleanup then raises before the provider
closes the sandbox, which runs on until its ttl_s.

nemo_gym.sandbox.stop_sandbox(), in the sandbox package's utils, shields the
stop from that cancellation and bounds it in time, so a hung provider
cannot hold the request either. A timed-out stop raises
TimeoutError, which owners treat like any other failed stop. It also accepts
a Compose group, which harbor owns.

LentSandboxes, the swebench sandbox session base and deepswe_external1 each
had a copy of this stop; they now use the shared one.

Signed-off-by: Ananth Subramaniam <[email protected]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the risk:high Autobot PR risk: high label Nov 18, 2026
Every sandbox has one owner, the server that starts it, but each server
family owns its sandboxes through its own design. Gym already has a class
that tracks a server's sandboxes by key, stops them, lends them with operate
scope and snapshots them for checkpoints: SandboxSessionCheckpointer, which
no server uses yet.

It becomes the public nemo_gym.server_runtime.OwnedSandboxes, in its own
module (nemo_gym/server_runtime/owned_sandboxes.py) since it is no longer
checkpoint-only, and every SimpleServer holds one as self.sandboxes:

- created on first use from the server's sandbox_provider and
  checkpoint.state_dir, so a server without sandboxes builds nothing
- self.sandboxes.on("<field>") gives the instance for a second provider
  field, with its own server name for the snapshot index
- run_webserver wraps the app's lifespan so the shutdown stops what every
  instance still owns, after the server's own shutdown code
- access() lends through the provider block the instance was built from
- the instance owns the provider it creates and closes it once every
  sandbox is stopped; it reads the config the server was started with
- the shutdown sweep runs after the server's own shutdown, is bounded
  (150 s in all), refuses to build new instances once it began, and is
  documented next to server_shutdown_timeout_seconds

The glossary gains "sandbox owner" and "lend / borrow", and its existing
"Owner" (the worker that holds a session) points away from them.

The class is renamed directly without an alias: it merged on 2026-11-16 and
is in no release.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub force-pushed the ananthsub/owned-sandboxes branch from c4b8ae6 to d72fc64 Compare November 18, 2026 23:19
@svcnvidia-nemo-ci svcnvidia-nemo-ci added feature New capabilities, enhancements, or enablement work area:sandbox Sandbox providers, isolation, and sandbox runtime contracts labels Nov 18, 2026
Base automatically changed from ananthsub/sandbox-shielded-stop to main November 19, 2026 16:42
@hemildesai
hemildesai added this pull request to stack #6695 November 24, 2026 05:17
yaoyu-33 and others added 2 commits November 23, 2026 21:37
Resolve against main:
- Drop this branch's earlier copy of the shielded stop (stop_sandbox() in
  nemo_gym.sandbox.utils and its test): #6410 merged a different version that
  puts the shield and limit in AsyncSandbox.stop(timeout_s=...). The sandbox
  package, LentSandboxes, the swebench session base and deepswe_external1
  take main's code; OwnedSandboxes stops through AsyncSandbox.stop.
- #5266 exports the checkpointer under its old name: its server, conformance
  helper and test move to OwnedSandboxes in owned_sandboxes, and the public
  API serves SandboxCheckpointConfig, SandboxCheckpointError and
  checkpoint_state_dir from there. No release shipped the old name.
- The glossary keeps main's sandbox lease and capabilities rows beside the
  owner and lend/borrow rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
OwnedSandboxes.for_server created the provider before it read
checkpoint.state_dir, so a refused config (checkpointing on without a
state_dir) left a provider nobody closes, and every later self.sandboxes
built another. The provider block and state_dir are now resolved first. An
owner on the local provider, which runs commands as host processes, logs a
warning.

The self.sandboxes docstring and the glossary say what is true today: no
server owns its sandboxes through it yet, it is used from the event loop, and
a borrower is an agent or a Resources Server grading in the sandbox. The
test imports names from their defining modules.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 24, 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 ed01ab7

@hemildesai

Copy link
Copy Markdown
Contributor

Review of d72fc64, as the bottom of the stack (#6415, #6416 and #6417 have their own comments). The behavior this PR adds works, including on a live OpenSandbox. I would hold it for the restack plus items 1 and 2 below. Each finding says whether I confirmed it with a test or run, or only read it from the code.

For the whole stack

A. The stack does not merge onto main, and main now disagrees with it in three places. Confirmed: git merge-tree origin/main origin/ananthsub/owned-sandboxes reports conflicts in 6 files (key-terminology.mdx, base_server.py, owned_sandboxes.py, sandbox_lending.py, deepswe_external1/app.py, swebench/sandbox_sessions.py). The descriptions already say a restack is pending; these are the three things it has to resolve beyond the text conflicts:

B. One repo-wide test fails on every head of the stack and passes on the base. Confirmed: tests/unit_tests/test_public_api_facades.py::test_the_librarys_tests_import_from_the_module_that_defines_each_name. The new tests import names from a package's public API instead of the defining module. On this PR: tests/unit_tests/server_runtime/test_owned_sandboxes.py:20 (OwnedSandboxes, SimpleServer from nemo_gym.server_runtime). tests/unit_tests/sandbox/test_stop_sandbox.py:20 is also listed and goes away with the earlier #6410 commit. The validation lists in the descriptions run test_import_linter_coverage.py but not this file.

C. The split reads well. Each head works without the one above it. This PR alone exposes self.sandboxes.create() and stop() without the shield and failed-start tracking that #6415 adds, which is fine while no server uses it, as long as #6415 lands before the first one does.

D. Nit. New lines across the stack use Optional[X]; AGENTS.md asks for X | None on added or changed lines.

This PR

1. High: the rename removes a name that main exports and uses. Read from code. nemo_gym/server_runtime/owned_sandboxes.py:385 renames SandboxSessionCheckpointer without an alias and the module nemo_gym/server_runtime/_checkpoint/sandbox.py goes away. On main, nemo_gym/server_runtime/__init__.py:230-232,255 exports SandboxCheckpointConfig, SandboxCheckpointError, SandboxSessionCheckpointer and checkpoint_state_dir from that module, resources_servers/swebench/sandbox_session_checkpoints.py:65,141 builds a SandboxSessionCheckpointer, and resources_servers/swebench/testing/checkpoint_conformance.py:26 imports the module. Restacked as written, the swebench resources server fails at import. Suggested fix: move the four _PUBLIC_API entries to owned_sandboxes, keep SandboxSessionCheckpointer importable with a deprecation warning through nemo_gym/_moved_paths.py (AGENTS.md asks for that when a public name is renamed), and move swebench onto the new name. The description's "its only other consumer is the open #5266" no longer holds.

2. Medium: drop the earlier shared stop when restacking. Read from code. nemo_gym/sandbox/utils.py:219-244 and the stop_sandbox / STOP_TIMEOUT_S exports in nemo_gym/sandbox/__init__.py duplicate what main has in nemo_gym/sandbox/api.py. The edits to sandbox_lending.py, deepswe_external1/app.py and swebench/sandbox_sessions.py belong to that commit too. Kept, they would give nemo_gym.sandbox a second public stop.

3. Low: a misconfigured provider shows at the first request, not at startup. Read from code, and the description says so. base_server.py:304-330 builds self.sandboxes on first use, so a misnamed provider block, or checkpointing without checkpoint.state_dir, fails the first seed. Resolving the block and checkpoint_state_dir() once in run_webserver when the config sets sandbox_provider, without creating the provider, would move both to startup.

The new tests assert real behavior against a fake provider (lazy creation, shutdown order, the sweep's budget, provider close).

What I ran on d72fc64

  • pytest tests/unit_tests/sandbox tests/unit_tests/server_runtime tests/unit_tests/agents tests/unit_tests/utils tests/unit_tests/test_import_linter_coverage.py -n 8: 4919 passed, 25 failed, 1 error. The same 26 ids fail on the stack's base commit 8c2c624 on my machine (macOS: uvicorn_reuse_port needs Linux, errno values, an old uv on PATH, no Ray extra), so none comes from this PR.
  • pytest tests/unit_tests/test_*.py: 1294 passed, 1 failed (item B).
  • pre-commit run --files <the 14 changed files>: passed, nothing modified.
  • Live OpenSandbox, a scratch script through the public API (not in the repo), 19 of 19 checks passed: self.sandboxes built on first use; two creates; a second create of a key refused; access() names the server's block and a borrower connects and runs in the lent sandbox; the lifespan shutdown stops both sandboxes on the service and closes the instance; export, then restore in a second instance (the fork has the file as it was at the snapshot, the superseded sandbox is stopped), then delete_snapshots empties the index. No sandbox was left on the service afterwards.
  • Not run: the deepswe_external1 and swebench server suites (touched only by the earlier fix(sandbox): shield and bound AsyncSandbox.stop and the other releases #6410 commit) and model rollouts (no server uses self.sandboxes yet).

@yaoyu-33

Copy link
Copy Markdown
Contributor

Follow-up to the review and verification record above, at 0f019e64f0 (the item-by-item table is on #6703: #6703 (comment)):

  • 1, the renamed class: SandboxSessionCheckpointer stays importable from nemo_gym.server_runtime as a deprecated alias of OwnedSandboxes until 0.10.0. b6f2750
  • 3, misconfiguration at the first request: a relative or unwritable checkpoint.state_dir is refused before the provider is built, and self.sandboxes no longer needs a state_dir at all for a server that never exports. The provider block of every block a server declares in owned_sandbox_blocks, and of a lending server, is resolved at startup by feat(sandbox): apply typed network rules through owner capabilities #6416's check.
  • D, Optional: the new module and its tests use X | None.
  • The review bot's three findings (snapshot index shared across provider fields, a provider built before a failing index check, a provider close that could not be retried) are fixed in 0f019e6, with regressions.

…-sandboxes' into codex/ready-6414

Signed-off-by: yaoyu-33 <[email protected]>

# Conflicts:
#	nemo_gym/server_runtime/owned_sandboxes.py
#	tests/unit_tests/server_runtime/test_owned_sandboxes.py
…x/ready-6414

Signed-off-by: yaoyu-33 <[email protected]>

# Conflicts:
#	nemo_gym/server_runtime/base_server.py
@yaoyu-33 yaoyu-33 changed the title feat(sandbox): make the sandbox checkpointer the public OwnedSandboxes feat(sandbox): expose the shared OwnedSandboxes owner Nov 24, 2026
@hemildesai

Copy link
Copy Markdown
Contributor

Re-review at 1f7f667

Tracking issue: #6703

I reread the commits pushed since my last comment and reran the live checks on this head. No new finding on this PR.

Addressed

  • The renamed class (my point 1): fixed. SandboxSessionCheckpointer still imports from nemo_gym.server_runtime and from the old module nemo_gym.server_runtime._checkpoint.sandbox, each with a DeprecationWarning, and is OwnedSandboxes (confirmed by importing all three paths on this head).
  • The shutdown sweep: aclose_sandboxes() is bounded by SANDBOX_SHUTDOWN_TIMEOUT_S (base_server.py:135). Confirmed with a provider whose stop hangs: with the limit set to 1 s the sweep returned after 1.00 s and the key stayed tracked.

Still open, low

Live check on this head: 19 of 19 pass against OpenSandbox (lazy creation, create, lend to a borrower, the shutdown sweep, then export, restore from the snapshot and release), and no sandbox was left.

The two regressions I found in this round are in #6416's merge, not here.

…and others borrow it

The owner description named a Resources Server as a lender of the attempt's sandbox on equal terms with the
Environment Server. The Environment Server owns the sandbox an attempt runs in and lends it to the agent and to
the Resources Server; a Resources Server owns a sandbox only for a grader that runs code in an attempt without one.
Today's Resources lenders and agent-owned harness sandboxes are described as what moves onto it. An export also
waits for borrowers' commands, not only the owner's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

Copy link
Copy Markdown
Contributor

/ok to test f053fa5

Resolve an explicitly configured sandbox_provider while loading the server config so an absent named block stops launch before a rollout is dispatched. Preserve defaults used by optional backends and keep provider construction lazy. Report only the type when a reference points at a scalar setting.

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

Copy link
Copy Markdown
Contributor

/ok to test e0c862c

@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team November 25, 2026 02:16
yaoyu-33
yaoyu-33 previously approved these changes Nov 25, 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.

Reviewed the sandbox owner lifecycle, checkpoint import compatibility, SWE-bench integration, and startup validation at e0c862c28.

I ran the one-row DeepSWE/OpenCode eval with sandbox_provider: sandbxo. Previously all four servers reported ready and the first seed failed. With the fix, the resources server reports the missing named block at startup, before rollout dispatch. Omitted optional defaults and inline provider settings retain their existing behavior.

Full pre-commit passed. The affected server runtime, sandbox, public API compatibility, and SWE-bench checkpoint suites reported 1,540 passed and 3 skipped. The negative eval stops before model inference. The new head’s CI is running.

Allow standalone server schemas to be inspected before the operator composes a provider block. Check the reference before launching a worker or returning from a dry run. Exercise both the schema-only load and actual startup with the same configuration.

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

Copy link
Copy Markdown
Contributor

/ok to test c46c9f4

@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 25, 2026 02:34

@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 the sandbox owner lifecycle, checkpoint compatibility, and the revised launch check at c46c9f4ea. Standalone recipes can still load before composition. When a server starts, Gym resolves its explicitly named provider against the composed config.

I ran the DeepSWE/OpenCode eval with one real task and the Docker provider. With sandbox_provider: sandbxo, the resources server reported the missing block before rollout dispatch. With sandbox_provider: sandbox, all four servers reached ready. The positive check covered startup only.

The workstation suites covering server runtime, sandbox, SWE-bench checkpoints, public APIs, and CritPt passed 3,590 tests with five skips. Full pre-commit passed.

The CI shard containing CritPt also passed. Two other server shards need a retry after GitHub refused dependency downloads for IFBench and NOOA during setup.

@yaoyu-33
yaoyu-33 enabled stacked auto-merge November 25, 2026 03:06
@hemildesai

Copy link
Copy Markdown
Contributor

Third review round at c46c9f4

Tracking issue: #6703

I read the three commits pushed since my last comment and reran the live check on this head.

Addressed

  • Misconfiguration at the first request (my earlier point 3): fixed. A server now resolves an explicitly named sandbox_provider when it launches (base_server.py:687), so a misnamed block is reported before the server is ready.

New, low: this is a behavior change worth a line in the compatibility notes. (read from code, and counted) The launch check also runs in a dry run. 107 shipped configs name sandbox as their provider and 4 of them define that block in the same file, so the rest rely on a provider config composed in at launch. That is the normal way to run them. A server that names a provider it uses only in some modes, for example an agent whose sandbox is lent by another server under a different block name, no longer starts without the named block. The code comment says only explicit names are checked because some modes leave a default unused; a name written in a shipped config is explicit too.

Live check on this head: 19 of 19 pass against OpenSandbox, and no sandbox was left.

No other finding on this PR.

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

Approving at c46c9f4. Three review rounds, the live OpenSandbox check (19 of 19) and pre-commit on this head; my findings on this PR are addressed. Details are in my comments above and in #6703.

One low item stays open and does not block: a server now resolves an explicitly named sandbox_provider when it launches, which deserves a line in the compatibility notes.

The failing CI checks are the ones marked non-blocking: the mini-SWE sandboxed conformance probe fails wherever it currently runs, including on main and on other open PRs.

@yaoyu-33
yaoyu-33 added this pull request to the merge queue Nov 25, 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/45564126056

@yaoyu-33 yaoyu-33 added ready-to-merge PR is approved, current, and waiting for final CI or merge and removed needs-review PR is ready for code review and waiting on a reviewer labels Nov 25, 2026
Merged via the queue into main with commit cd1b05d Nov 25, 2026
220 of 239 checks passed
@yaoyu-33
yaoyu-33 deleted the ananthsub/owned-sandboxes branch November 25, 2026 07:12
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 ready-to-merge PR is approved, current, and waiting for final CI or merge risk:high Autobot PR risk: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants