Typical flow
Methods
sb.SSH()
Example
Example
Returns
SSH client and server helpers for this sandbox.
ssh.OpenClient()
Example
Example
root, terminal from $TERM (falling back to xterm), and SFTP enabled.
Parameters
ctxcontext.ContextCancels the connection attempt.
opts…SSHClientOptionLogin user, terminal name, and SFTP toggle.
Returns
Native SSH client session.
error
Typed microsandbox error.
ssh.PrepareServer()
Example
Example
SSHServer can serve connections one at a time over the process’s standard streams.
Parameters
ctxcontext.ContextCancels server preparation.
opts…SSHServerOptionHost key, authorized keys, guest user, and SFTP toggle.
Returns
Prepared server endpoint.
error
Typed microsandbox error.
c.Exec()
Example
Example
WithSSHTTY is passed.
Parameters
ctxcontext.ContextCancels the exec request.
commandstringCommand string sent through SSH.
opts…SSHExecOptionPTY toggle for the exec channel.
Returns
Captured stdout, stderr, and exit status.
error
Typed microsandbox error.
c.Attach()
Example
Example
Parameters
ctxcontext.ContextCancels the attach session.
opts…SSHAttachOptionTerminal name and detach key sequence.
Returns
int
Shell exit code (128 if terminated by signal).
error
Typed microsandbox error.
c.SFTP()
Example
Example
Parameters
ctxcontext.ContextCancels opening the SFTP session.
Returns
SFTP client session.
error
Typed microsandbox error.
c.Close()
Example
Example
Parameters
ctxcontext.ContextCancels the close.
Returns
error
Typed microsandbox error.
srv.ServeConnection()
Example
Example
SSHServer to serve another connection.
Parameters
ctxcontext.ContextCancels serving the connection.
Returns
error
Typed microsandbox error.
srv.Close()
Example
Example
Parameters
ctxcontext.ContextCancels the close.
Returns
error
Typed microsandbox error.
o.Success()
Example
Example
0.
Returns
bool
true when Status is 0.Types
SandboxSSHOps
Returned by SSH()
SSH operations namespace for a sandbox. Obtained viasb.SSH(). Holds no resources; it groups the client and server entry points.
| Method | Returns | Description |
|---|---|---|
OpenClient(ctx, opts...) | (*SSHClient, error) | Open a native in-process SSH client |
PrepareServer(ctx, opts...) | (*SSHServer, error) | Prepare a reusable SSH server endpoint |
SSHClient
Returned by OpenClient()
A native in-process SSH client session. Obtained viaOpenClient().
| Method | Returns | Description |
|---|---|---|
Exec(ctx, command, opts...) | (*SSHOutput, error) | Run a command and collect output |
Attach(ctx, opts...) | (int, error) | Bridge the local terminal to an interactive shell |
SFTP(ctx) | (*SFTPClient, error) | Open an SFTP session over this connection |
Close(ctx) | error | Close the session (consumes the handle) |
SFTPClient
Returned by SFTP()
A high-level SFTP client session over an SSH connection. Obtained viaSFTP().
| Method | Returns | Description |
|---|---|---|
| Read(ctx, path) | ([]byte, error) | Read a file into memory |
| Write(ctx, path, data) | error | Write a file, creating or truncating it |
| Mkdir(ctx, path) | error | Create a directory |
| RemoveFile(ctx, path) | error | Remove a file |
| RemoveDir(ctx, path) | error | Remove an empty directory |
| Rename(ctx, oldPath, newPath) | error | Rename a file or directory |
| RealPath(ctx, path) | (string, error) | Resolve a path to its canonical absolute form |
| ReadLink(ctx, path) | (string, error) | Read a symlink target |
| Symlink(ctx, target, linkPath) | error | Create a symlink |
| Close(ctx) | error | Close the session (consumes the handle) |
SSHServer
Returned by PrepareServer()
A prepared SSH server endpoint for a sandbox. Obtained viaPrepareServer().
| Method | Returns | Description |
|---|---|---|
ServeConnection(ctx) | error | Serve one SSH transport over stdin/stdout |
Close(ctx) | error | Release the endpoint (consumes the handle) |
SSHOutput
Returned by Exec()
The output from an SSH exec request.| Field / Method | Type | Description |
|---|---|---|
| Status | int | Exit status code |
| Stdout | []byte | Captured stdout bytes |
| Stderr | []byte | Captured stderr bytes |
Success() | bool | true when Status is 0 |
SSHClientOption
Used by OpenClient()
Functional option forOpenClient(). Defaults: user root, terminal from $TERM (falling back to xterm), SFTP enabled.
| Option | Description |
|---|---|
| WithSSHUser(user) | SSH login user. Default root |
| WithSSHTerm(term) | Terminal name for interactive sessions |
| WithSSHClientSFTP(enabled) | Enable or disable SFTP on the internal server. Default true |
SSHExecOption
Used by Exec()
Functional option forExec().
| Option | Description |
|---|---|
| WithSSHTTY(enabled) | Request a PTY for the exec channel |
SSHAttachOption
Used by Attach()
Functional option forAttach(). The default terminal comes from $TERM (falling back to xterm); detach keys default to the standard sequence.
| Option | Description |
|---|---|
| WithSSHAttachTerm(term) | Terminal name for the interactive shell |
| WithSSHDetachKeys(keys) | Detach key sequence |
SSHServerOption
Used by PrepareServer()
Functional option forPrepareServer(). SFTP is enabled by default; when no authorized-keys path is provided, the default authorized-keys file is loaded.
| Option | Description |
|---|---|
| WithSSHHostKeyPath(path) | Override the host private key path |
| WithSSHAuthorizedKeysPath(path) | Override the authorized-keys path |
| WithSSHServerUser(user) | Override the guest user used for SSH exec requests |
| WithSSHServerSFTP(enabled) | Enable or disable SFTP on the server endpoint. Default true |