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.

Sandbox


SSH()

func (s *Sandbox) SSH() *SSH
Return the SSH namespace for this sandbox. Returns
TypeDescription
*SSHSSH client and server helpers

SSH


Connect()

func (ssh *SSH) Connect(ctx context.Context, opts ...SSHClientOption) (*SSHClient, error)
Connect a native in-process SSH client to the sandbox. Parameters
NameTypeDescription
ctxcontext.ContextCancels the connection attempt
opts...SSHClientOptionClient options
Returns
TypeDescription
*SSHClientNative SSH client session
errorTyped microsandbox error

Server()

func (ssh *SSH) Server(ctx context.Context, opts ...SSHServerOption) (*SSHServer, error)
Prepare a reusable SSH server endpoint. Parameters
NameTypeDescription
ctxcontext.ContextCancels server preparation
opts...SSHServerOptionServer options
Returns
TypeDescription
*SSHServerServer endpoint
errorTyped microsandbox error

SSHClient


Exec()

func (c *SSHClient) Exec(ctx context.Context, command string, opts ...SSHExecOption) (*SSHOutput, error)
Run an SSH exec request and collect stdout, stderr, and exit status. Parameters
NameTypeDescription
ctxcontext.ContextCancels the exec request
commandstringCommand string sent through SSH
opts...SSHExecOptionExec options
Returns
TypeDescription
*SSHOutputCaptured output and status
errorTyped microsandbox error

Attach()

func (c *SSHClient) Attach(ctx context.Context, opts ...SSHAttachOption) (int, error)
Attach the local terminal to an interactive SSH shell. Parameters
NameTypeDescription
ctxcontext.ContextCancels the attach session
opts...SSHAttachOptionAttach options
Returns
TypeDescription
intExit code
errorTyped microsandbox error

SFTP()

func (c *SSHClient) SFTP(ctx context.Context) (*SFTPClient, error)
Open an SFTP session over this SSH connection. Returns
TypeDescription
*SFTPClientSFTP client session
errorTyped microsandbox error

Close()

func (c *SSHClient) Close(ctx context.Context) error
Close the native SSH client session. The handle is consumed.

SFTPClient

MethodReturnsDescription
Read(ctx, path)([]byte, error)Read a file into memory
Write(ctx, path, data)errorCreate or truncate a file
Mkdir(ctx, path)errorCreate a directory
RemoveFile(ctx, path)errorRemove a file
RemoveDir(ctx, path)errorRemove an empty directory
Rename(ctx, oldPath, newPath)errorRename a file or directory
RealPath(ctx, path)(string, error)Resolve a canonical path
ReadLink(ctx, path)(string, error)Read a symlink target
Symlink(ctx, target, linkPath)errorCreate a symlink
Close(ctx)errorClose the SFTP session

SSHServer


ServeStdio()

func (srv *SSHServer) ServeStdio(ctx context.Context) error
Serve one SSH transport over stdin/stdout.

Close()

func (srv *SSHServer) Close(ctx context.Context) error
Release the prepared server endpoint. The handle is consumed.

Types

SSHOutput

Field / MethodTypeDescription
StatusintExit status code
Stdout[]byteCaptured stdout bytes
Stderr[]byteCaptured stderr bytes
Success()booltrue if status is 0

SSHClientOption

OptionDescription
WithSSHUser(user)SSH login user. Defaults to root
WithSSHTerm(term)Terminal name for interactive sessions
WithSSHClientSFTP(enabled)Enable or disable SFTP on the internal server

SSHExecOption

OptionDescription
WithSSHTTY(enabled)Request a PTY for the exec channel

SSHAttachOption

OptionDescription
WithSSHAttachTerm(term)Terminal name for the shell
WithSSHDetachKeys(keys)Detach key sequence

SSHServerOption

OptionDescription
WithSSHHostKeyPath(path)Override the host private key path
WithSSHAuthorizedKeysPath(path)Override the authorized-keys path
WithSSHServerUser(user)Override the guest user used for exec requests
WithSSHServerSFTP(enabled)Enable or disable SFTP