nemo_gym.agents.utils.sandbox_session
nemo_gym.agents.utils.sandbox_session
Supervised harness activations over one retained sandbox connection.
Module Contents
Classes
Functions
Data
API
Bases: Exception
expire cannot stop this running harness: its sandbox’s uploads can wait for capacity the harness holds.
Harness argv, run under the bash process supervisor.
Execute, stop, capture, then release an owned or borrowed sandbox.
Runtime installation belongs in the adapter’s seed hook. stage_activation
stages input and returns a command; collect copies harness artifacts
to the agent server after cleanup is confirmed. It may run a bounded snapshot
command, but must not restart the harness. Parsing responses stays in the adapter.
Each activation stages input and a fresh supervisor, runs the harness process, then
stops and collects artifacts. Adapters may explicitly rearm it with begin_activation
after confirmed cleanup, retaining native state outside the per-activation directory.
The default still permits only one launch. Execution retains the sandbox until close
releases it. Missing termination evidence remains retryable. A final negative
receipt skips capture, releases a borrowed connection and leaves teardown to
Resources; an owned sandbox falls back to provider stop. Closed means release succeeded.
The supervisor stops the harness process group; a forced stop also reaches the
harness’s descendants in other groups and processes that inherited its
NEMO_GYM_SUPERVISOR marker. Processes that had left the harness when the stop
began, processes in other groups after a natural exit, and a process that left
between two scans without the marker remain until the sandbox owner destroys the
sandbox.
Borrowed sandboxes stay available for Resources verification; owned sandboxes are
stopped on close. Unconfirmed harness termination prevents capture and verification.
Each stop, collection and release phase is bounded by close_timeout (or
the timeout passed to close). Failed cleanup/release retains the handle
for retry. Failed capture is recorded separately and does not prevent release.
HTTP request binding and activation retries belong to the agent session layer.
Whether no launch occurred, termination was witnessed, or owned sandbox stopped.
Whether sandbox release completed successfully.
Whether close has been requested, including a failed attempt.
Whether expire ended this activation; its receipt then records the timeout.
Whether expire kept the harness from starting, so it left no output to collect.
Marker path an adapter may pass to its harness for cancellation diagnostics.
Keep a stop whose marker write failed only if the marker is in place and the receipt timed out.
A write still in flight is awaited first, so a failure that arrives during finalization is checked too.
The whole check, including any wait for provider capacity, is bounded by timeout; without a
confirmation the stop stays unattributed and finalization goes on. That includes a write still in flight
when the bound runs out: the harness may have ended at its own deadline, before any marker arrived.
Join process finalization without releasing the sandbox connection.
Write the marker the supervisor watches, within timeout including any wait for the provider.
A file write, not an exec: a provider that bounds its concurrent execs (Local) counts the harness’s own launch against that bound for as long as it runs, and a stop must not wait for the harness to end.
Rearm a stopped harness using fresh supervisor files in the same sandbox.
The adapter retains its native conversation elsewhere in the sandbox. A previous launch must be reaped before any activation fields can be reset. Close fences all later activations, including when release needs retry.
Join finalization before release; concurrent/retried closes never duplicate capture.
Run once, preserving captured artifacts even when execution raises.
Cancellation stops the remote harness before releasing provider exec. Callers that merely stop waiting (such as disconnected HTTP requests) must shield their shared activation task.
End the harness as at its time limit, so its receipt records timed_out.
Unlike stop_harness (a cancellation), the activation is then graded like a timeout.
A request made before launch ends the harness as it would launch. Returns False when the
activation already finished, the session is closing, or expiry was already requested.
Stopping a running harness takes an upload, which on a provider without
SupportsSandboxIndependentUploads can wait behind the very commands it must stop, so there it
raises ExpiryUnsupportedError. A request before launch works on every provider.
Read combined supervisor/harness diagnostics without masking the original failure.
Confirm harness termination before capture and transport release.
Bash source assigning each value, for sandbox runners that cannot parse JSON.
A string becomes a scalar and a sequence an array. A mapping becomes an array of
KEY=VALUE words, ready for export or env. Every word is shell-quoted.
Words must be strings without NUL, which bash cannot hold.