Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.microsandbox.dev/llms.txt

Use this file to discover all available pages before exploring further.

See SSH for usage flows.
microsandbox = { version = "0.4.6", features = ["ssh"] }

Sandbox


ssh()

fn ssh(&self) -> SandboxSsh
Return the SSH namespace for this sandbox. Returns
TypeDescription
SandboxSshSSH client and server helpers

SandboxSsh


connect()

async fn connect(&self) -> MicrosandboxResult<SshClient>
Connect a native in-process SSH client to the sandbox. Returns
TypeDescription
SshClientNative SSH client session

connect_with()

async fn connect_with(
    &self,
    f: impl FnOnce(SshClientOptionsBuilder) -> SshClientOptionsBuilder,
) -> MicrosandboxResult<SshClient>
Connect a native SSH client with custom client options. Parameters
NameTypeDescription
fFnOnce(SshClientOptionsBuilder) -> SshClientOptionsBuilderConfigure user, terminal, and SFTP support
Returns
TypeDescription
SshClientNative SSH client session

server()

async fn server(&self) -> MicrosandboxResult<SshServer>
Prepare a reusable SSH server endpoint for this sandbox. Returns
TypeDescription
SshServerReusable SSH server endpoint

server_with()

async fn server_with(
    &self,
    f: impl FnOnce(SshServerOptionsBuilder) -> SshServerOptionsBuilder,
) -> MicrosandboxResult<SshServer>
Prepare a server endpoint with custom host-key, authorization, user, or SFTP options. Parameters
NameTypeDescription
fFnOnce(SshServerOptionsBuilder) -> SshServerOptionsBuilderConfigure server options
Returns
TypeDescription
SshServerReusable SSH server endpoint

SshClient


exec()

async fn exec(&self, command: impl Into<String>) -> MicrosandboxResult<SshOutput>
Run an SSH exec request and collect stdout, stderr, and exit status. Parameters
NameTypeDescription
commandimpl Into<String>Command string sent through SSH
Returns
TypeDescription
SshOutputCaptured output and status

exec_with()

async fn exec_with(
    &self,
    command: impl Into<String>,
    f: impl FnOnce(SshExecOptionsBuilder) -> SshExecOptionsBuilder,
) -> MicrosandboxResult<SshOutput>
Run an SSH exec request with options. Parameters
NameTypeDescription
commandimpl Into<String>Command string sent through SSH
fFnOnce(SshExecOptionsBuilder) -> SshExecOptionsBuilderConfigure exec options
Returns
TypeDescription
SshOutputCaptured output and status

attach()

async fn attach(&self) -> MicrosandboxResult<i32>
Attach the local terminal to an interactive SSH shell. Returns
TypeDescription
i32Exit code

attach_with()

async fn attach_with(
    &self,
    f: impl FnOnce(SshAttachOptionsBuilder) -> SshAttachOptionsBuilder,
) -> MicrosandboxResult<i32>
Attach with terminal options. Parameters
NameTypeDescription
fFnOnce(SshAttachOptionsBuilder) -> SshAttachOptionsBuilderConfigure terminal and detach keys
Returns
TypeDescription
i32Exit code

sftp()

async fn sftp(&self) -> MicrosandboxResult<SftpClient>
Open an SFTP session over this SSH connection. Returns
TypeDescription
SftpClientSFTP client session

close()

async fn close(self) -> MicrosandboxResult<()>
Close the native SSH client session.

SshServer


serve()

async fn serve<S>(&self, stream: S) -> MicrosandboxResult<()>
where
    S: AsyncRead + AsyncWrite + Unpin + Send + 'static
Serve one SSH connection over an ordered duplex stream. Parameters
NameTypeDescription
streamSOrdered duplex SSH transport

Types

SshOutput

FieldTypeDescription
statusi32Exit status code
stdoutBytesCaptured stdout bytes
stderrBytesCaptured stderr bytes

SftpClient

Alias for russh_sftp::client::SftpSession.

SshClientOptionsBuilder

MethodParametersDescription
user()impl Into<String>SSH login user. Defaults to root
term()impl Into<String>Terminal name for interactive sessions
sftp()boolEnable or disable SFTP on the internal server

SshExecOptionsBuilder

MethodParametersDescription
tty()boolRequest a PTY for the exec channel

SshAttachOptionsBuilder

MethodParametersDescription
term()impl Into<String>Terminal name for the shell
detach_keys()impl Into<String>Detach key sequence

SshServerOptionsBuilder

MethodParametersDescription
host_key_path()impl Into<PathBuf>Override the host private key path
host_key()PrivateKeyUse an in-memory host private key
authorized_keys_path()impl Into<PathBuf>Override the authorized-keys path
authorized_key()impl Into<String>Add one in-memory authorized public key
user()impl Into<String>Override the guest user used for exec requests
sftp()boolEnable or disable SFTP