nemo_gym.server_runtime.sandbox_lending
nemo_gym.server_runtime.sandbox_lending
The sandboxes a resources server lends to a harness, one per resources session.
Module Contents
Classes
Functions
Data
API
Start, lend and stop one sandbox per resources session, from the server’s sandbox configuration.
A server’s episode seed calls lend and its episode close calls release, both under the server’s
ResourcesSessionLocks lock. The server keeps any other session state, such as task files it serves or a
tool workspace, and calls release_all at shutdown. A server that grades in the lent sandbox after the
episode reads it with get before the close.
The harness gets an operate descriptor, which asks the provider to let it use the sandbox but not destroy it
(providers without leases ignore the scope). A stop goes on when the request that asked for it is cancelled, and
gives up after STOP_TIMEOUT_S. A session that is never closed keeps its sandbox until shutdown, or until the
provider reclaims it after sandbox_config.ttl_s, so set ttl_s above the episode deadline plus the time
that grading and cleanup take. A sandbox from a failed seed whose stop also fails is kept apart from the lent
ones, and the session’s next lend, its release or the shutdown tries the stop again.
With network_access="model_only", each sandbox is created with an egress rule that allows only the host of
model_server, the model server that a harness in the sandbox calls. model_and_tools also allows the hosts
of tool_servers, the servers whose tools the harness calls over MCP, such as this resources server. Every port
of an allowed host is open, so other services on that host stay reachable. The harness that borrows the sandbox
keeps this network; it cannot change it.
The egress rule for network_access, refused (422) where it cannot be enforced.
It allows the model server’s host, and for model_and_tools the tool servers’ hosts too.
Stop the sandbox a failed seed of the session left running, if any. A failed stop raises and keeps it.
Return the sandbox lent for resources_session_id, or None.
Return the access a harness needs to the session’s sandbox, and start the sandbox on the first call.
files maps absolute paths in the sandbox to their contents; it can be empty. A repeated call, as for a
repeated seed, returns the same sandbox. If the new sandbox cannot start, receive its files or be described,
it is stopped and the error is raised. If that stop fails too, the sandbox is kept for a later stop: the
session’s next lend stops it before it starts another one, and a failed stop there fails the lend.
Stop the session’s sandbox; safe to repeat. A failed stop raises and keeps it, so a close can retry.
It also stops a sandbox that a failed seed of the session left running.
Stop every sandbox still lent, as at server shutdown. A failed stop is logged and the rest go on.
Stop sandbox within STOP_TIMEOUT_S, even while the request that owns it is being cancelled.
A client that disconnects cancels its request handler and every later await in it, so an unshielded stop would never run, and the sandbox would outlive every reference to it.