Skip to main content
Reach a running sandbox over SSH: open a native in-process SSH client, run exec requests, attach an interactive shell, transfer files over SFTP, or stand up a reusable server endpoint that serves connections over stdin/stdout. See SSH for usage flows.

Sandbox

sb.ssh()

Return the SSH namespace for this sandbox. The namespace holds the SSH client and server helpers; nothing connects until you call open_client() or prepare_server(). This method is synchronous; the helpers it returns are async.

Returns

SSH namespace for this sandbox.

SandboxSshOps

Returned by sb.ssh()

SSH operations for a sandbox.

ssh.open_client()

Connect a native in-process SSH client to this sandbox. Generates an ephemeral client and host key pair, stands up an internal server bound to an in-memory stream, and authenticates over public key.

Parameters

userstr
SSH login user. Default “root”.
termstr | None
Terminal name for interactive sessions. Defaults to $TERM.
sftpbool
Enable or disable SFTP on the internal server. Default True.
inactivity_timeoutfloat | None
Disconnect after this many seconds without SSH traffic. 0 disables the timeout; None inherits the global setting.

Returns

Connected SSH client session.

ssh.prepare_server()

Prepare a reusable SSH server endpoint for this sandbox. Loads or creates the host key and resolves authorized keys, falling back to the default authorized-keys file when no path is given. The returned SshServer serves one connection over this process’s stdin/stdout.

Parameters

host_key_pathstr | os.PathLike[str] | None
Override the host private key path.
authorized_keys_pathstr | os.PathLike[str] | None
Override the authorized-keys path.
userstr | None
Override the guest user used for exec requests.
sftpbool
Enable or disable SFTP. Default True.
inactivity_timeoutfloat | None
Disconnect after this many seconds without SSH traffic. 0 disables the timeout; None inherits the global setting.

Returns

Reusable SSH server endpoint.

SshClient

Returned by ssh.open_client()

Native in-process SSH client session. A connected, native in-process SSH client session, obtained from ssh.open_client().

client.exec()

Run an SSH exec request and collect stdout, stderr, and the exit status. The command runs through the sandbox’s configured shell. When tty=True a PTY is allocated and stderr is folded into stdout.

Parameters

commandstr
Command string sent through SSH.
ttybool
Request a PTY for the exec channel. Default False.

Returns

Captured output and exit status.

client.attach()

Attach the local terminal to an interactive SSH shell. Requests a PTY sized to the current terminal, puts the terminal into raw mode, forwards keystrokes, and returns when the shell exits or the detach key sequence is typed.

Parameters

termstr | None
Terminal name for the shell. Defaults to $TERM.
detach_keysstr | None
Detach key sequence, e.g. “ctrl-p,ctrl-q”.

Returns

int
Shell exit code (128 if terminated by signal).

client.sftp()

Open an SFTP client session over this SSH connection. Requests the sftp subsystem and returns a high-level session for reading, writing, and listing files inside the guest.

Returns

SFTP client session.

client.close()

Close this native SSH client session. Sends a disconnect and aborts the internal server task.

SshServer

Returned by ssh.prepare_server()

Reusable SSH server endpoint for a sandbox. A reusable SSH server endpoint for a sandbox, obtained from ssh.prepare_server().

server.serve_connection()

Serve one SSH transport over this process’s stdin/stdout. Runs the SSH handshake and session loop to completion, returning when the connection closes. Use this to bridge an SSH connection over the parent process’s standard streams.

server.close()

Release this prepared server endpoint. This method is synchronous.

SftpClient

Returned by client.sftp()

High-level SFTP client session over an SSH connection. All methods are async.

sftp.read()

Read a file into memory.

Returns

bytes

sftp.write()

Write a file, creating or truncating it.

sftp.mkdir()

Create a directory.

sftp.remove_file()

Remove a file.

sftp.remove_dir()

Remove an empty directory.

sftp.rename()

Rename a file or directory.

sftp.real_path()

Resolve a path to its canonical absolute form.

Returns

str
Read a symlink target.

Returns

str
Create a symlink.

sftp.close()

Close the SFTP session.

Types

SshOutput

Returned by client.exec()

Output from an SSH exec request.