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. See SSH for usage flows.

Sandbox

sb.SSH()

Return the SSH operations namespace for this sandbox. The namespace groups the client and server helpers; it holds no resources of its own.

Returns

SSH client and server helpers for this sandbox.

SandboxSSHOps

Returned by SSH()

SSH operations namespace for a sandbox. Obtained via sb.SSH(). Holds no resources; it groups the client and server entry points.

ssh.OpenClient()

Open 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. With no options it uses login user root, terminal from $TERM (falling back to xterm), and SFTP enabled.

Parameters

ctxcontext.Context
Cancels the connection attempt.
Login user, terminal name, SFTP toggle, and inactivity timeout.

Returns

Native SSH client session.
error
Typed microsandbox error.

ssh.PrepareServer()

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 unless overridden. The returned SSHServer can serve connections one at a time over the process’s standard streams.

Parameters

ctxcontext.Context
Cancels server preparation.
Host key, authorized keys, guest user, SFTP toggle, and inactivity timeout.

Returns

Prepared server endpoint.
error
Typed microsandbox error.

SSHClient

Returned by OpenClient()

A native in-process SSH client session. Obtained via OpenClient().

c.Exec()

Run an SSH exec request and collect stdout, stderr, and the exit status. The command is run through the sandbox’s configured shell. No PTY is requested unless WithSSHTTY is passed.

Parameters

ctxcontext.Context
Cancels the exec request.
commandstring
Command string sent through SSH.
PTY toggle for the exec channel.

Returns

Captured stdout, stderr, and exit status.
error
Typed microsandbox error.

c.Attach()

Bridge 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 detach key sequence is typed.

Parameters

ctxcontext.Context
Cancels the attach session.
Terminal name and detach key sequence.

Returns

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

c.SFTP()

Open an SFTP session over this SSH connection. Returns a high-level SFTP client for reading, writing, and managing files inside the guest. Requires SFTP enabled on the client (the default).

Parameters

ctxcontext.Context
Cancels opening the SFTP session.

Returns

SFTP client session.
error
Typed microsandbox error.

c.Close()

Close this SSH client session. The handle is consumed; do not use it after closing.

Parameters

ctxcontext.Context
Cancels the close.

Returns

error
Typed microsandbox error.

SSHServer

Returned by PrepareServer()

A prepared SSH server endpoint for a sandbox. Obtained via PrepareServer().

srv.ServeConnection()

Serve one SSH transport over this process’s stdin and stdout. Returns when the connection ends. Call again on the same SSHServer to serve another connection.

Parameters

ctxcontext.Context
Cancels serving the connection.

Returns

error
Typed microsandbox error.

srv.Close()

Release this prepared server endpoint. The handle is consumed; do not use it after closing.

Parameters

ctxcontext.Context
Cancels the close.

Returns

error
Typed microsandbox error.

SSHOutput

Returned by Exec()

The output from an SSH exec request.

o.Status

int Exit status code

o.Stdout

[]byte Captured stdout bytes

o.Stderr

[]byte Captured stderr bytes

o.Success()

Report whether the command exited with status 0.

Returns

bool
true when Status is 0.

SFTPClient

Returned by SFTP()

A high-level SFTP client session over an SSH connection. Obtained via SFTP().

sftp.Read()

Read a file into memory

Returns

([]byte, error)

sftp.Write()

Write a file, creating or truncating it

Returns

error

sftp.Mkdir()

Create a directory

Returns

error

sftp.RemoveFile()

Remove a file

Returns

error

sftp.RemoveDir()

Remove an empty directory

Returns

error

sftp.Rename()

Rename a file or directory

Returns

error

sftp.RealPath()

Resolve a path to its canonical absolute form

Returns

(string, error)
Read a symlink target

Returns

(string, error)
Create a symlink

Returns

error

sftp.Close()

Close the session (consumes the handle)

Returns

error

Types

SSHClientOption

Used by OpenClient()

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

SSHExecOption

Used by Exec()

Functional option for Exec().

SSHAttachOption

Used by Attach()

Functional option for Attach(). The default terminal comes from $TERM (falling back to xterm); detach keys default to the standard sequence.

SSHServerOption

Used by PrepareServer()

Functional option for PrepareServer(). SFTP is enabled by default, the inactivity timeout inherits the global SSH setting, and the default authorized-keys file is loaded when no path is provided.