nemo_gym.sandbox.providers.base
nemo_gym.sandbox.providers.base
Provider-facing sandbox protocol.
Module Contents
Classes
Data
API
Optional capability: rebuild a handle in another process from a descriptor.
Providers whose sandboxes are reachable by id (external control plane, e.g.
OpenSandbox and Fargate, and the sandbox server’s remote provider) implement
this. A provider that does not implement it can only be shared by fronting it
with a sandbox server. Membership is checked with isinstance because the
protocol is runtime_checkable.
Rebuild a live handle in this process from a descriptor.
Return a JSON-serializable descriptor that connect can rebuild a
handle from. scope is honored by providers that mint leases (the
remote provider) and ignored by the rest.
Bases: RuntimeError
Raised when a provider cannot create a sandbox.
Bases: SandboxCreateError
Raised when a newly-created sandbox fails provider readiness checks.
Provider-neutral route to a long-lived service inside a sandbox.
endpoint is an absolute URL. headers carries provider-required
authentication or routing headers without exposing the provider’s opaque
handle to callers.
Provider-neutral process execution result.
return_code is the process exit code when the sandbox actually ran the
command. Providers may use a non-process sentinel with error_type set
when the sandbox runtime reports an execution failure without a process
exit code.
Provider-neutral handle to a created sandbox.
raw is provider-owned opaque state. Public code should pass it back to
the provider through this handle rather than inspecting or mutating it
directly.
Runtime/infra provider contract used by the public sandbox API.
Close provider-scoped resources such as SDK clients.
End the sandbox lifecycle and close provider resources for it.
Create a ready sandbox and return a provider-neutral handle.
Providers must return only after the sandbox is healthy enough to run
commands and transfer files. If the sandbox cannot become ready before
the configured timeout, providers should raise SandboxCreateError
or a provider-specific subclass.
Download one sandbox file to the local filesystem.
Run a command inside a sandbox.
Return the current sandbox lifecycle status.
Upload one local file into a sandbox.
Bases: RuntimeError
Raised when a PTY session fails outside normal process exit.
One live interactive terminal. Async context manager; exit closes it.
Whether close() has run; a closed session cannot run commands.
"pty" or "pipe" once connected, None before that. Only pipe
mode splits stderr; in PTY mode all output arrives through read().
Yield output chunks until EOF.
Idempotent: release local resources; a session this client created is also ended, while an attached one is merely detached and lives on for its owner.
Return the next output chunk (all terminal output in PTY mode;
stdout only in pipe mode). b"" means the process exited and the
stream is drained. Raises TimeoutError on timeout and
SandboxPtyError if the session died without exiting.
Return the next stderr chunk. Only pipe mode (pty=False)
carries stderr separately; in PTY mode this stream is empty and
returns b"" once the process exits. Same timeout/error semantics
as read().
Resize the terminal.
Deliver a named signal, e.g. "SIGTERM", to the session’s process
group. Interactive shells run foreground jobs in their own group, so
signals reliably reach the process only for command sessions; whether
SIGINT interrupts at all also depends on the sandbox runtime’s
inherited signal dispositions.
Block until the process exits and return its exit code.
Send raw bytes to the terminal’s stdin.
Interactive PTY session request.
command runs under the backend’s interactive shell; None spawns the
shell itself. Backends without native env/user support may rewrite the
command (mirroring exec()’s user rewrite) and must raise ValueError
for values they cannot honor. pty=False selects pipe mode: no TTY,
stdout and stderr delivered as separate streams, rows/cols ignored.
Backends that cannot size a terminal at spawn apply rows/cols as
soon as it connects, so a command reading the size immediately may
observe the backend default.
Provider-neutral resource request.
Sandbox creation request.
Bases: enum.Enum
Provider-neutral sandbox lifecycle status.
Optional provider capability for resolving declared service ports.
Resolve a declared service port to a caller-reachable endpoint.
Optional provider capability: interactive PTY sessions.
Open an interactive terminal inside a sandbox.
Optional provider capability: re-attach to a PTY session by id.
Separate from SupportsSandboxPty because it requires sessions that live
in the sandbox rather than in the client, so a provider may offer terminals
without offering re-attach.
Re-attach to an existing session by id.
takeover evicts the current holder, whose session then fails with
SandboxPtyError; without it, attaching to a held session fails.
since is a byte offset into the session’s retained output to replay
before live output (0 replays everything still retained).