Repository navigation
feat(environment): require a sandbox provider for BaseEnvironmentServerWithTools and add start_episode_sandbox - #5917
Merged
Conversation
Contributor
Author
|
/ok to test f18ed16 |
This was referenced Nov 10, 2026
ffrujeri
force-pushed
the
ffrujeri/self-contained-sandbox
branch
from
November 10, 2026 06:12
f18ed16 to
95fe617
Compare
Contributor
Author
|
/ok to test 95fe617 |
ffrujeri
force-pushed
the
ffrujeri/self-contained-sandbox
branch
from
November 10, 2026 06:43
95fe617 to
fd5d6cc
Compare
Contributor
Author
|
/ok to test fd5d6cc |
Contributor
ffrujeri
force-pushed
the
ffrujeri/self-contained-sandbox
branch
from
November 10, 2026 18:03
fd5d6cc to
e660930
Compare
Contributor
Author
|
/ok to test e660930 |
ffrujeri
force-pushed
the
ffrujeri/self-contained-sandbox
branch
from
November 13, 2026 18:11
bafbbde to
a87c8ac
Compare
Contributor
Author
|
/ok to test a87c8ac |
adil-a
approved these changes
Nov 16, 2026
ffrujeri
force-pushed
the
ffrujeri/self-contained-sandbox
branch
from
November 16, 2026 17:08
a87c8ac to
26e7f04
Compare
Contributor
Author
|
/ok to test 26e7f04 |
ffrujeri
force-pushed
the
ffrujeri/self-contained-sandbox
branch
from
November 16, 2026 17:57
26e7f04 to
e584c93
Compare
Contributor
Author
|
/ok to test e584c93 |
ffrujeri
enabled stacked auto-merge
November 16, 2026 19:14
kajalj22
approved these changes
Nov 16, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Nov 16, 2026
Base automatically changed from
ffrujeri/self-contained-session-routing
to
main
November 16, 2026 20:08
…erWithTools and add start_episode_sandbox An episode of a BaseEnvironmentServerWithTools has a control plane, the server, which decides what a tool call runs, and a data plane, the episode's sandbox, which runs every operation on the episode's world. The control plane never runs such an operation in its own process. - BaseEnvironmentServerWithToolsConfig.sandbox_provider is required, so every environment says where its data plane runs. A provider that the config does not define fails at startup. The local provider runs commands as host subprocesses, so the server logs a warning at startup. - start_episode_sandbox(request, cleanup, spec, setup) starts a sandbox for the episode. It requires ttl_s, labels the sandbox with the server's name and the episode's rollout over the provider's and the spec's metadata, and registers the stop in the episode's cleanup before it starts the sandbox, so the cleanup or the shutdown sweep also stops a sandbox whose start or first stop failed. A failed setup stops the sandbox. - The class docstring states the control plane and data plane rule. A runtime check that refuses process creation and sqlite3 in the control plane is left for a follow-up (GYMINT-733). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Felipe Vieira Frujeri <[email protected]>
…t Server example BaseEnvironmentServerWithToolsConfig now requires sandbox_provider, so the example would fail validation without it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Felipe Vieira Frujeri <[email protected]>
…up handle start_episode_sandbox stopped such a sandbox with a direct call, which the cleanup timeout did not bound and the episode's cleanup repeated. It now closes the registered handle: the stop gets the cleanup timeout and the entry's lock, a stop that succeeded is not run again, and one that failed or timed out stays for the episode's cleanup to retry. The docstring now names the providers that ignore ttl_s (Docker with a custom entrypoint, Apptainer, Enroot and local). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Felipe Vieira Frujeri <[email protected]>
ffrujeri
force-pushed
the
ffrujeri/self-contained-sandbox
branch
from
November 16, 2026 20:08
e584c93 to
55cb90a
Compare
Contributor
Author
|
/ok to test 55cb90a |
ffrujeri
enabled stacked auto-merge
November 16, 2026 22:14
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/43969961580 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #5350 (session routing). The stack: #5346 (episode tokens) → #5347 (the base class) → #5348 (shutdown sweep) → #5349 (MCP) → #5350 (session routing) → this PR. Review those first; this PR's diff against #5350 is the sandbox requirement. The BIRD-Interact stack (#5465 → #5409 → …) sits on this PR, and #5409 is the first environment that uses it.
What changed
An episode of a
BaseEnvironmentServerWithToolshas two planes:The control plane never runs such an operation in its own process. This PR makes every environment say where its data plane runs, and gives it one way to start an episode's sandbox.
sandbox_provideris required onBaseEnvironmentServerWithToolsConfig: a provider block name, such assandbox, or an inline mapping, such as{docker: {}}. A name that the config does not define fails at startup.locallogs a warning at startup. The local provider runs commands as host subprocesses, with no isolation. An environment that runs on the host chooseslocalexplicitly and gets the warning; this includes an environment that never starts a sandbox.start_episode_sandbox(request, cleanup, spec, setup, *, name="sandbox")starts a sandbox for the episode:spec.ttl_s, so the provider reclaims the sandbox if the server dies.spec.metadata, thennemo_gym_environment(the server's name) androllout_id(the episode's capture key), each truncated to 63 characters.sandbox.stopin the episode's cleanup before it starts the sandbox. The episode's cleanup, or the shutdown sweep from feat(environment): finish every Environment Server's running cleanups at shutdown #5348, then also stops a sandbox whose start or first stop failed.setupfails, it stops the sandbox and raises. If that stop fails, it logs the failure and the episode's cleanup tries again.sandbox_provider, which it now needs to validate.A runtime check that refuses process creation and
sqlite3in the control plane is a follow-up (Linear GYMINT-733). It was left out to keep this version light, because its cost at scale is unknown.Why
Linear GYMINT-734. Nothing in the base class told a subclass to put the work that tools do in a sandbox, and each environment started and stopped its sandboxes by hand. A sandbox gives each episode crash and security isolation for that work. The helper puts the rules from
AGENTS.md's Sandbox section in one place: provider from config, metadata merge order, short labels,ttl_s, and a stop on every path.Validation
pytest tests/unit_tests/server_runtime/test_base_environment_server_with_tools.py tests/unit_tests/server_runtime/test_episode_tools_session_routing.pypytest -n 12 tests/unit_tests/server_runtime/ tests/unit_tests/agents/ tests/unit_tests/test_public_api.py tests/unit_tests/test_import_linter_coverage.py tests/unit_tests/test_moved_paths.pyNEMO_GYM_MULTIWORKER_E2E=1 pytest tests/e2e/session_routing/test_episode_tools_routing_e2e.pypre-commit runon the changed filesNew tests in
test_base_environment_server_with_tools.py, with a fakeAsyncSandbox:sandbox_providerfails validation.locallogs the startup warning;dockerdoes not.ttl_sis refused.Each new behavior was broken on purpose, and its test failed:
localttl_scheckRollout evidence
N/A for this PR: it adds a config field and a helper to a base class that no environment on
mainuses yet. BIRD-Interact (#5409) moves its sandboxes ontostart_episode_sandbox, and its rollouts run in that stack.Compatibility
BaseEnvironmentServerWithToolsconfigs must now setsandbox_provider. No server onmainsubclasses the class yet. Gym's own test servers, the session-routing tests and the e2e server set{local: {}}.BaseEnvironmentServerand other server types do not change.