nemo_gym.sandbox.providers.opensandbox.pty
nemo_gym.sandbox.providers.opensandbox.pty
execd PTY sessions over the OpenSandbox server proxy.
Speaks execd’s documented PTY wire protocol directly: the
released OpenSandbox SDKs expose no PTY API. Sessions live at
{base}/pty[/{session_id}[/ws]] where base is the sandbox’s execd
endpoint as resolved by the SDK (through the server proxy when
use_server_proxy is set).
execd sends the exit frame and closes the socket concurrently with its output pumps, so a clean EOF means the socket drained, not that every byte the process wrote was delivered. Callers that need the tail should have the command emit a sentinel and read until it appears.
Module Contents
Classes
Functions
Data
API
One live PTY WebSocket. Created via :func:open_pty_session.
True once the session can no longer run commands: after close(),
or once the connection pump has ended (process exit, takeover eviction,
or connection loss). A detach()-ed session is not closed: the
server side keeps running and reattach() restores it. Resources
are released by close().
Sole reader of the session’s sockets; fans frames out to queue/future.
A socket that dies while the process still runs (proxy shed, connection
loss) is re-dialed with since=<bytes received>, so pending reads and
execs continue across the gap. A deliberate takeover, a protocol error,
an exit, or close() ends the session instead.
Drain one WebSocket until it closes, fanning frames out.
Re-dial the session’s WebSocket, resuming from the last received byte.
Drop the WebSocket while the server-side session keeps running.
Output produced while detached lands in execd’s replay buffer (a 1 MiB
ring; older bytes are evicted), and reattach() resumes from the
last byte this object saw. A detached session refuses reads and
writes; close() still releases it (and ends it when owned).
Re-dial a detach()-ed session, replaying output produced since.
Run one command holding the socket only for brief polls.
The command is written with the same marker discipline as session
exec, the socket is dropped, and every poll_interval_s the session
re-attaches and drains output produced in the meantime from the
server’s retained window. Nothing is written to the sandbox
filesystem; if the command produced more output between polls than
the server retains, the loss is detected and raised rather than
returned truncated. Returns (output, exit_code) — output is one
merged stream (replayed bytes carry no stdout/stderr split) and
exit_code is None when the marker line came back mangled.
The session ends attached. Callers serialize: one command per
session at a time, as with session exec.
Rewrite env/user into the command: execd’s PTY create accepts only
cwd and command.
Attach to an existing execd PTY session. Owns client as above.
Create an execd PTY session and attach its WebSocket.
Owns client: it is closed on failure and by session.close().