nemo_gym.sandbox.providers
nemo_gym.sandbox.providers
Sandbox provider registry.
Subpackages
nemo_gym.sandbox.providers.apptainernemo_gym.sandbox.providers.daytonanemo_gym.sandbox.providers.dockernemo_gym.sandbox.providers.e2bnemo_gym.sandbox.providers.ecs_fargatenemo_gym.sandbox.providers.enrootnemo_gym.sandbox.providers.localnemo_gym.sandbox.providers.opensandboxnemo_gym.sandbox.providers.openshell
Submodules
nemo_gym.sandbox.providers.basenemo_gym.sandbox.providers.registrynemo_gym.sandbox.providers.utils
Package Contents
Classes
Functions
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.
error_type="user_switch_unavailable" means the provider confirmed that
credential switching prevented process launch. Helpers that allow the image’s
default user can choose that branch without reporting a failure event.
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. New and migrated providers must report allocation
and readiness failures as NgFailureEvent with boundary="sandbox" and a registered kind.
Providers awaiting migration still expose creation exceptions; see the
sandbox documentation’s required provider migrations.
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 when this wait expires;
that alone does not mean the command failed. Report session death as
NgFailureEvent; providers awaiting migration use SandboxPtyError.
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.
Run one command holding the transport only for brief completion
polls; returns (merged output, exit code or None). The server
retains a bounded window of output between polls, and exceeding it
raises rather than returning truncated output.
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.
Raises TimeoutError when this wait expires; that alone does not mean
the command failed. Session failures follow the same contract as read.
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.
Bases: SandboxResourceAmounts
Provider-neutral creation request, retaining integer memory/disk inputs.
An extra container started with the sandbox from its own image.
The sidecar has its own filesystem. Start services in it with AsyncSandbox.sidecar(name).exec.
How the sandbox reaches a sidecar over the network is provider-specific.
Sandbox creation request.
Bases: enum.Enum
Provider-neutral sandbox lifecycle status.
Optional execution override for services needed by a later command.
Optional provider capability for resolving declared service ports.
Resolve a declared service port to a caller-reachable endpoint.
Optional provider capability: a file upload never waits for capacity that running commands hold.
A provider that bounds its concurrent operations with one limit shared by commands and file transfers
(CLI slots, worker threads, pooled connections) cannot promise this: once long-running commands hold every
slot, an upload waits until one of them ends. SandboxSession.expire needs it to stop a running harness,
because the stop is a file the harness’s supervisor watches for. The answer may depend on configuration.
Optional direct networking between sandboxes, preserving service ports.
Optional provider capability to pause and resume a sandbox.
What survives a pause beyond the filesystem is backend-specific.
Pause a sandbox while preserving its state.
Resume a paused sandbox and refresh its handle.
Optional loopback TCP forwarding, running until cancellation.
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).
Optional per-sandbox image pull policy: always, missing or never (Compose’s pull_policy).
pull_policy_options returns the provider_options that apply it at create time. A provider
without this capability leaves the pull behaviour to the deployment’s default.
Optional validation and setup of task-declared runtime requirements.
Validate support and return any required create-time metadata.
Optional container settings a Compose service declares: tmpfs, ulimits, sysctls, security_opt.
SERVICE_OPTION_FIELDS names the subset the provider can apply; it is a class attribute so prepare
can check a task against a provider by name, without instantiating it. service_options returns
the provider_options that apply the given values at create time (an empty mapping when none are
given) and raises ValueError for a value it cannot express.
Optional shared filesystem provisioned by the operator’s provider config.
shared_volume_options returns provider options containing a volumes
list of opaque mount descriptors. Collections concatenate these lists.
source is relative to the configured shared root; None mounts that
root for initialization and cleanup. Metadata supplies placement settings.
Optional provider capability to run sidecar containers next to the sandbox.
The provider creates the sidecars declared in SandboxSpec.sidecars together with the sandbox, then runs
commands in them and reads files from them through these calls. Commands run as an argv without a shell,
because sidecar images can be distroless.
Download one file from sidecar to the local filesystem.
Run argv in sidecar; on_stdout receives stdout text as it arrives, for long-running services.
Cap each scheduling request at the limit the spec declares for the same key.
Kubernetes never schedules a pod whose request exceeds its limit, and OpenSandbox reports such a
sandbox only as “pending allocation”, so a request above a task’s declared limit must not reach the
create call. Returns the requests with the offending keys set to their limit, and
{key: (request, limit)} for the keys that changed so the caller can log a warning naming them.
Keys the limits do not declare pass through untouched.
Instantiate a provider from a single-key provider config.
Return a provider class by name (explicit > built-in > entry point).
List available provider names from all sources.
The Compose service options (tmpfs, ulimits, sysctls, security_opt) provider name can apply.
Read from the provider class’s SERVICE_OPTION_FIELDS (see SupportsSandboxServiceOptions), so
prepare can check a task against the deployment’s provider without instantiating it. A provider
without the attribute applies none of them.
Register a sandbox provider class.