nemo_gym.server_runtime.sandbox_borrow
nemo_gym.server_runtime.sandbox_borrow
How a borrower uses a sandbox another server lends it: borrow.
Every sandbox has one owner, the server that started it, and only the owner stops it (see “Sandbox owner” in the
glossary). A borrower, an agent whose seed carries a sandbox_access or a Resources Server grading in the sandbox,
runs commands and transfers files in it, and releases its client when it is done. Lent access is always operate scope.
No provider enforces scope yet, so the refusals are advisory: code that connects to a sandbox some other way, or
calls the raw provider a borrowed sandbox still exposes as .provider (its close, pause and snapshot),
can still stop it. Enforcement waits on provider leases; until then every borrower should connect through
borrow. Agents that call AsyncSandbox.connect themselves move onto it one by one, and a repository check
that keeps connections inside borrow and OwnedSandboxes follows once they have.
Module Contents
Classes
Functions
Data
API
Bases: AsyncSandbox
A lent sandbox: commands, terminals and file transfers work, the owner’s lifecycle operations refuse.
Commands and terminal sessions run as the access’s user in its workdir, with its env under each
call’s own env. That includes a harness’s own setup, such as installing its runtime: a command that must run
as another user names it. stop, start, pause, resume and snapshot raise
BorrowedSandboxError. disconnect releases the client, shielded from cancellation and bounded as
AsyncSandbox.disconnect is, and leaving an async with block disconnects instead of stopping. Sidecar
commands run in another container and take none of the access’s settings.
The access this sandbox was lent with, for a harness that borrows it again, for example in a subprocess.
That borrower calls borrow with it, and with named_configs holding the provider block that
access.connection.provider_config_ref names, since a subprocess has no global config.
Raises:
RuntimeError: For a sandbox thatborrowdid not build.
Run command as AsyncSandbox.exec does, with the access’s env under env.
The access’s user is passed explicitly when the call names none, since a command that keeps background
services runs through a provider call that does not read the sandbox’s default user.
Refuse: pausing is the owner’s, for example at a checkpoint.
Refuse: resuming is the owner’s.
A descriptor with operate scope; access wraps it for a harness that borrows it elsewhere.
Raises:
ValueError: Ifscopeasks for more than operate scope.
Refuse: the owner snapshots the sandbox at a checkpoint.
Refuse: a borrower never creates a sandbox.
Refuse: a borrower never creates a sandbox.
Refuse: the owner stops the sandbox. Release this client with disconnect.
Bases: RuntimeError
A borrower tried what only the sandbox’s owner does: start, stop, pause, resume or snapshot it.
Bases: SandboxPty
Terminal sessions of a borrowed sandbox, with the access’s env under each session’s own.
Connect to the sandbox access lends, as its borrower.
The provider is resolved from access.connection.provider_config_ref in named_configs, the merged global
config by default. The returned sandbox runs commands as access.user in access.workdir with
access.env, and its client is released with BorrowedSandbox.disconnect. A connect that fails or is
cancelled closes the client it opened, shielded from the cancellation, and raises the connect’s own error.
Raises:
ValueError: If the provider config cannot be resolved.RuntimeError: If the provider cannot reconnect to a sandbox.