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 SSH server endpoint. Requires the ssh feature. 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 connect or server.

Returns

SSH namespace for this sandbox.

SandboxSshOps

Returned by sb.ssh()

SSH operations for a sandbox.

ssh.connect()

Connect a native in-process SSH client to this sandbox. Generates an ephemeral Ed25519 client and host key pair, stands up an internal server bound to a duplex stream, and authenticates over public key. Uses default client options (user root, terminal from $TERM, SFTP enabled).

Returns

Connected SSH client session.

ssh.open_client()

Alias for connect.

Returns

Connected SSH client session.

ssh.connect_with()

Connect a native in-process SSH client with custom options. The closure configures the login user, terminal name, whether SFTP is enabled on the internal server, and the SSH inactivity timeout.

Parameters

Configure user, terminal, SFTP support, and the inactivity timeout.

Returns

Connected SSH client session.

ssh.open_client_with()

Alias for connect_with.

Parameters

Configure user, terminal, SFTP support, and the inactivity timeout.

Returns

Connected SSH client session.

ssh.server()

Prepare a reusable SSH server endpoint for this sandbox. Loads or creates the host key and resolves authorized keys from the default authorized-keys file. The returned SshServer is cloneable and can serve many connections.

Returns

Reusable SSH server endpoint.

ssh.prepare_server()

Alias for server.

Returns

Reusable SSH server endpoint.

ssh.server_with()

Prepare a server endpoint with custom host-key, authorization, guest-user, SFTP, or inactivity-timeout options. If no authorized keys are configured, the default authorized-keys file is loaded; an empty key set is an error.

Parameters

Configure host key, authorized keys, guest user, SFTP, and the inactivity timeout.

Returns

Reusable SSH server endpoint.

ssh.prepare_server_with()

Alias for server_with.

Parameters

Configure host key, authorized keys, guest user, and SFTP.

Returns

Reusable SSH server endpoint.

SshClient

Returned by ssh.connect(), ssh.connect_with()

Native in-process SSH client session.

client.exec()

Run an SSH exec request and collect stdout, stderr, and the exit status. The command is run through the sandbox’s configured shell (default /bin/sh -c). No PTY is requested.

Parameters

commandimpl Into<String>
Command string sent through SSH.

Returns

Captured output and exit status.

client.exec_with()

Run an SSH exec request with options. The closure can request a PTY via tty; when a PTY is allocated, stderr is folded into stdout.

Parameters

commandimpl Into<String>
Command string sent through SSH.
Configure exec options.

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, relays window-resize events, and returns when the shell exits or the default detach key sequence is typed.

Returns

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

client.attach_with()

Attach an interactive shell with custom terminal and detach-key options.

Parameters

Configure terminal name and detach keys.

Returns

i32
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 SFTP 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. Consumes the client.

SshServer

Returned by ssh.server(), ssh.server_with()

Reusable SSH server endpoint for a sandbox.

server.serve()

Serve one SSH connection over an ordered duplex stream. Runs the SSH handshake and session loop to completion. Returns when the connection closes.

Parameters

streamS: AsyncRead + AsyncWrite
Ordered duplex SSH transport.

server.serve_connection()

Alias for serve.

Parameters

streamS: AsyncRead + AsyncWrite
Ordered duplex SSH transport.

SshStdioStream

Used by server.serve()

Ordered duplex stream backed by this process’s stdin and stdout. Implements AsyncRead and AsyncWrite.

SshStdioStream::new()

Create a stdio SSH transport stream backed by this process’s stdin and stdout. Implements AsyncRead and AsyncWrite, so it can be passed straight to serve to bridge an SSH connection over the parent process’s standard streams. Also available via Default.

Returns

Duplex stream over stdin/stdout.

Constants

DEFAULT_SSH_HOST

Default SSH listener host used by the CLI adapter when binding a sandbox SSH endpoint.

DEFAULT_SSH_PORT

Default SSH listener port used by the CLI adapter when binding a sandbox SSH endpoint.

SshClientOptionsBuilder

Used by ssh.connect_with()

Builder for SSH client options. Defaults: user root, terminal from $TERM (falling back to xterm), SFTP enabled, and the global SSH inactivity timeout.

client_options.user()

SSH login user. Default root.

client_options.term()

Terminal name for interactive sessions.

client_options.sftp()

Enable or disable SFTP on the internal server. Default true.

client_options.inactivity_timeout()

Override the internal server inactivity timeout. Duration::ZERO disables it.

client_options.disable_inactivity_timeout()

Disable the internal server inactivity timeout.

client_options.build()

Finalize the options.

SshExecOptionsBuilder

Used by client.exec_with()

Builder for SSH exec options.

exec_options.tty()

Request a PTY for the exec channel. Default false.

exec_options.build()

Finalize the options.

SshAttachOptionsBuilder

Used by client.attach_with()

Builder for interactive SSH attach options. Default terminal comes from $TERM (falling back to xterm); detach keys default to the standard sequence.

attach_options.term()

Terminal name for the shell.

attach_options.detach_keys()

Detach key sequence.

attach_options.build()

Finalize the options.

SshServerOptionsBuilder

Used by ssh.server_with()

Builder for SSH server options. SFTP is enabled by default; the inactivity timeout inherits the global SSH setting; when no authorized keys are provided, the default authorized-keys file is loaded.

server_options.host_key_path()

Override the host private key path.

server_options.host_key()

Use an in-memory host private key.

server_options.authorized_keys_path()

Override the authorized-keys path.

server_options.authorized_key()

Add one in-memory authorized public key.

server_options.user()

Override the guest user used for exec requests.

server_options.sftp()

Enable or disable SFTP. Default true.

server_options.inactivity_timeout()

Override the SSH inactivity timeout. Duration::ZERO disables it.

server_options.disable_inactivity_timeout()

Disable the SSH inactivity timeout.

server_options.build()

Finalize the options.

SftpClient

Returned by client.sftp()

High-level SFTP client session.

Types

SshOutput

Returned by client.exec(), client.exec_with()

Output from an SSH exec request.