nemo_gym.sandbox.providers.docker.provider
nemo_gym.sandbox.providers.docker.provider
Docker sandbox provider: one long-lived container per sandbox, driven via the docker CLI.
Module Contents
Classes
Functions
Data
DOCKER_CREATE_TRANSPORT_ERROR_MARKERS
DOCKER_MISSING_CONTAINER_MARKERS
API
Bases: SandboxCreateError
Raised when Docker cannot create a sandbox.
Bases: SandboxCreateVerificationError
Raised when a new container fails its readiness probe.
Sandbox provider backed by the local Docker CLI / daemon.
Return state for an exact owned container, None when it cannot be resolved.
The docker exec command line of one PTY session: interactive, with a terminal in PTY mode.
The session’s marker (NEMO_GYM_PTY_SESSION=<session id>) goes last among the --env flags so no
spec env can override it: it is how the recorded pid is known to be this session’s process.
Recover the exact Sandbox-owned container after an ambiguous docker run.
One session of _release_pty_sessions; a failure is logged, never raised into the caller.
Close (or, when the container goes away, abandon) the live sessions of container name.
Configured exec shell, else bash when the image has it (for conda source), else sh.
Run a docker CLI command as (return_code, stdout, stderr); SIGKILL the group on timeout.
Run docker run without leaking a container when its response is lost.
A fixed, random name makes retry idempotent. After a timeout, transport error, or same-name conflict, inspect that exact name before retrying. Reuse it only when both the Sandbox ownership label and requested image match; never remove an unrelated collision.
Finish a docker run that created its container but lost the start response.
Poll the readiness probe until it passes stable_count times or the deadline elapses.
Close the PTY sessions still open; the containers themselves belong to their handles.
Force-remove the container (already-gone counts as success); its PTY clients are released first.
Create a handle for an existing running container, rediscovering its image and shell via the Docker CLI.
sandbox_id is required. AsyncSandbox.serialize() adds a
top-level ports key from the original spec; read it back here so
endpoint() still works after reconnecting.
Start a detached keep-alive container (image ENTRYPOINT overridden) and probe readiness.
spec.ttl_s bounds the lifetime (the keep-alive sleeps for it and --rm self-removes on
exit). spec.provider_options may carry volumes (-> -v) and run_args (extra run
flags). A half-created container is force-removed on any failure.
Open an interactive terminal in the container: one docker exec -it client under a host pty.
cwd, env and user map to the exec flags, rows/cols size the terminal before the
client starts, pty=False runs the client on pipes. The client process is not counted against
exec.concurrency: it lives as long as the session. The session’s pid is recorded under /tmp in the
container (under /dev/shm when /tmp refuses the write, as under create.read_only: true; a session
that can record it nowhere ends at once with a message instead of running unsignallable), read as the
session’s own user and signalled as root (no CAP_SYS_PTRACE needed). This returns as soon as the client
is spawned: send_signal()/close() wait up to two seconds for the record when they come first, refuse
at once a record that is not a regular file, and read it under a timeout of their own
(PID_READ_TIMEOUT_S) rather than exec.default_timeout_s. A client that exits without having started
the program (the daemon refused the exec: the container paused or gone, the daemon unreachable, told by the
client’s stderr as exec() tells a runtime failure) ends the session with SandboxPtyError from
wait_exit() and read() rather than as the program’s exit; a container closed while the session was
being opened has it abandoned and SandboxPtyError raised here. See nemo_gym.sandbox.providers.docker.pty.
Download one container file to the host.
Resolve a dynamically-published TCP port through the Docker daemon.
Run <shell> -c <command> via docker exec; never raises for command failure.
user maps to --user (root/0 -> 0). A timeout kills the local docker client only; the
in-container process is reaped when the sandbox is closed.
Compose’s pull_policy as docker run --pull; only always, missing and never exist.
Return a descriptor for reattaching to this container by id.
Docker recovers image and shell from the running container on connect,
and docker exec runs inside the container’s own environment, so the
id alone is enough; AsyncSandbox.serialize() layers the declared
ports on top. scope is unused by the Docker provider.
Compose service options as run_args: --tmpfs, --ulimit, --sysctl, --security-opt.
Container status via docker inspect (missing -> STOPPED; error/timeout -> UNKNOWN).
Upload one host file (creates the parent dir; the file lands owned by root).
Parse one docker port binding such as 127.0.0.1:49153.
argv copy with --env KEY=VALUE values masked, so timeouts/logs don’t leak secrets.
--user value: root/0 becomes 0, anything else is passed as written (name, uid, uid:gid).