nemo_gym.sandbox.providers.openshell.provider
nemo_gym.sandbox.providers.openshell.provider
OpenShell sandbox provider: sandboxes managed by an OpenShell gateway (github.com/NVIDIA/OpenShell).
The provider talks to the gateway’s gRPC control plane through the synchronous openshell
SDK; blocking SDK calls run on a thread pool bounded by exec.concurrency. The client and
thread pool are cached at module scope keyed on the connection config, so concurrent sandboxes
created from identical provider configs share one gRPC channel and one pool instead of
allocating one per sandbox. The SDK has no file-transfer API, so uploads stream bytes through
exec stdin (chunked to stay under the gateway’s gRPC message size limit) and downloads
round-trip through base64 on the sandbox’s stdout.
Module Contents
Classes
Functions
Data
SANDBOX_NAME_RANDOM_HEX_LENGTH
API
Gateway connection settings. Defaults target a local plaintext gateway (deploy/docker compose).
Bases: SandboxCreateError
Raised when the OpenShell gateway cannot create a sandbox.
Bases: SandboxCreateVerificationError
Raised when a new sandbox fails its readiness probe.
Sandbox provider backed by an OpenShell gateway’s gRPC control plane.
Run CreateSandbox on a worker. Cancelling the await does not stop a call already running, so a create that commits after the cancel is deleted when it returns.
Issue CreateSandbox, retrying transient gRPC failures with the same name.
Retrying with the same name is safe: if an earlier attempt actually committed, the retry fails ALREADY_EXISTS and the sandbox is recovered via GetSandbox.
Delete this process’s orphaned sandboxes: ones it no longer tracks, for example a create cancelled after the gateway committed it. Selected by the process label, which needs attribution to be enabled.
Run the SDK exec and time it inside the worker thread, so executor queueing is not counted.
Poll the readiness probe until it passes stable_count times or the deadline elapses.
Poll GetSandbox until READY, raising on the ERROR/DELETING phases or the deadline.
Release the shared client/pool (closed for real when the last provider releases it).
Does not wait for deletes: they run on their own workers. When no sandbox of this process is still
live or being created, it first deletes this process’s orphaned sandboxes (see _reap_orphans).
Hand the sandbox’s delete to a worker thread and return without waiting for the gateway.
The worker deletes, waits until the sandbox is gone when operations.close_wait_deleted is set, and
retries transient failures. It is already queued when this returns and runs to completion at interpreter
exit even if the event loop is gone. Every outcome is logged with the sandbox name; a delete that fails
for good is logged as possibly leaked and then forgotten.
Create a sandbox through the gateway, wait for the READY phase, then probe exec readiness.
spec.image is optional (the gateway’s configured default image is used when unset).
spec.ttl_s is not enforced (OpenShell sandboxes live until deleted) and only logs a
warning. spec.entrypoint is unsupported: the OpenShell supervisor owns the sandbox
entrypoint. spec.provider_options accepts providers (OpenShell credential-provider
names), policy (a SandboxPolicy mapping or YAML path), and template_resources /
driver_config (free-form driver passthrough Structs). A half-created sandbox is
deleted on any failure.
Download one sandbox file via a base64 round-trip (binary-safe over the text exec stream).
The whole file is buffered in memory (inflated 4/3 by base64), so this is intended for small-to-medium artifacts rather than large archives.
Run <shell> -c <command> through the gateway’s streaming exec; never raises for command failure.
The timeout is enforced by the gateway (timeout_seconds); the SDK extends its gRPC
deadline past it. user is ignored with a warning: the OpenShell exec API has no user
field, so commands run as the sandbox’s default user.
Sandbox phase via GetSandbox (missing -> STOPPED; RPC failure -> UNKNOWN).
Upload one local file by streaming its bytes through exec stdin (creates the parent dir).
Bytes are sent in exec.upload_chunk_bytes chunks because each chunk travels as a
single gRPC message that must stay under the gateway’s max decode size.
Validated per-sandbox options carried in SandboxSpec.provider_options.
One gRPC client + worker pool shared by every provider with the same connection config.
Delete one sandbox and (optionally) wait until it is gone, logging the outcome; runs in a worker thread.
A client deadline does not cancel a delete the gateway has already started, so after one the worker waits for
the sandbox to disappear and only re-issues the delete if it is still there; allow_missing makes the
re-issue idempotent. Transient transport failures and FAILED_PRECONDITION (a create’s driver operation is
still pending) are retried until operations.close_timeout_s. Each job can use up to
MAX_DELETE_ATTEMPTS delete deadlines, plus retry delays and the deletion wait.
Whether the exec stream ended at the timeout_seconds the provider passed it.
The 0.1.x exec stream reports the timeout as exit code 124 with no timeout flag. The gateway
only ends the stream; it does not kill the process, which may keep running in the sandbox. Only elapsed time
tells it from a command that exits 124 on its own, so a quick exit 124 is not a timeout.
The sandbox’s reported conditions as a message suffix (the gateway’s own reason, e.g. a pull failure).
Return a DNS-safe name within OpenShell’s routable-name limit.
The grpc.StatusCode of an RPC error, else None.
Transient transport failures, or FAILED_PRECONDITION while a create’s driver operation is pending.
Whether a CreateSandbox RPC failure is likely transient (safe to retry with the same name).
SandboxPhase -> SandboxStatus, built from the SDK’s generated proto constants.
Poll GetSandbox until NOT_FOUND (transient RPC failures keep polling until the deadline).