Typical flow
Sandbox
sb.ssh()
Example
Example
open_client() or prepare_server(). This method is synchronous; the helpers it returns are async.
Returns
SSH namespace for this sandbox.
SandboxSshOps
SSH namespace for a sandbox, obtained fromsb.ssh(). SSH is only supported on local sandboxes.
ssh.open_client()
Example
Example
Parameters
userstrSSH login user. Default
“root”.termstr | NoneTerminal name for interactive sessions. Defaults to
$TERM.sftpboolEnable or disable SFTP on the internal server. Default
True.Returns
Connected SSH client session.
ssh.prepare_server()
Example
Example
SshServer serves one connection over this process’s stdin/stdout.
Parameters
host_key_pathstr | os.PathLike[str] | NoneOverride the host private key path.
authorized_keys_pathstr | os.PathLike[str] | NoneOverride the authorized-keys path.
userstr | NoneOverride the guest user used for exec requests.
sftpboolEnable or disable SFTP. Default
True.Returns
Reusable SSH server endpoint.
SshClient
A connected, native in-process SSH client session, obtained fromssh.open_client().
client.exec()
Example
Example
tty=True a PTY is allocated and stderr is folded into stdout.
Parameters
commandstrCommand string sent through SSH.
ttyboolRequest a PTY for the exec channel. Default
False.Returns
Captured output and exit status.
client.attach()
Example
Example
Parameters
termstr | NoneTerminal name for the shell. Defaults to
$TERM.detach_keysstr | NoneDetach key sequence, e.g.
“ctrl-p,ctrl-q”.Returns
int
Shell exit code (128 if terminated by signal).
client.sftp()
Example
Example
sftp subsystem and returns a high-level session for reading, writing, and listing files inside the guest.
Returns
SFTP client session.
client.close()
Example
Example
SshServer
A reusable SSH server endpoint for a sandbox, obtained fromssh.prepare_server().
server.serve_connection()
Example
Example
server.close()
Example
Example
Types
SandboxSshOps
Returned by sb.ssh()
SSH namespace for a sandbox.| Method | Returns | Description |
|---|---|---|
open_client() | SshClient | (async) Open a client. |
prepare_server() | SshServer | (async) Prepare a server endpoint. |
SshClient
Returned by ssh.open_client()
Native in-process SSH client session.| Method | Returns | Description |
|---|---|---|
exec(command, *, tty=False) | SshOutput | (async) Run a command. |
attach(*, term=None, detach_keys=None) | int | (async) Interactive shell. |
sftp() | SftpClient | (async) Open an SFTP session. |
close() | None | (async) Close the session. |
SshServer
Returned by ssh.prepare_server()
Reusable SSH server endpoint for a sandbox.| Method | Returns | Description |
|---|---|---|
serve_connection() | None | (async) Serve one connection over stdin/stdout. |
close() | None | Release the prepared endpoint. |
SftpClient
Returned by client.sftp()
High-level SFTP client session over an SSH connection. All methods are async.| Method | Returns | Description |
|---|---|---|
| read(path) | bytes | Read a file into memory. |
| write(path, data) | None | Write a file, creating or truncating it. |
| mkdir(path) | None | Create a directory. |
| remove_file(path) | None | Remove a file. |
| remove_dir(path) | None | Remove an empty directory. |
| rename(old_path, new_path) | None | Rename a file or directory. |
| real_path(path) | str | Resolve a path to its canonical absolute form. |
| read_link(path) | str | Read a symlink target. |
| symlink(target, link_path) | None | Create a symlink. |
| close() | None | Close the SFTP session. |
SshOutput
Returned by client.exec()
Output from an SSH exec request.| Property | Type | Description |
|---|---|---|
| status | int | Exit status code. |
| success | bool | Whether the command exited successfully. |
| stdout_text | str | Stdout as UTF-8 text. |
| stderr_text | str | Stderr as UTF-8 text. |
| stdout_bytes | bytes | Stdout as raw bytes. |
| stderr_bytes | bytes | Stderr as raw bytes. |