Documentation
¶
Overview ¶
Package sandboxconnect opens an interactive terminal to a sandbox over the WebSocket its execution API serves at /terminal/ws. That endpoint is not in the API spec: it takes JSON messages of type input, output, resize, and error, with the token, window size, and session ID in the URL.
A session survives transport loss. An idle sandbox hibernates, and the VM pause kills the connection without a close frame. Run reports the loss and, on the next keystroke, reconnects with the same session ID, which reattaches to the shell the session left and replays its buffered output.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DialOptions ¶
type DialOptions struct {
// SandboxURL is the sandbox's URL.
SandboxURL string
// NewToken returns a sandbox token, told the token the sandbox API just
// rejected, if any. A reconnection after a long hibernation may outlive
// the first token.
NewToken sandbox.TokenProvider
// Input is read and sent to the sandbox's shell.
Input io.Reader
// Output receives the shell's output.
Output io.Writer
// Errors receives the terminal errors the sandbox reports.
Errors io.Writer
// Terminal is the local terminal, or nil for none: an 80 by 24 window,
// with no raw mode and no resizing.
Terminal TerminalControl
}
DialOptions are the options for Dial.
type Terminal ¶
type Terminal struct {
// contains filtered or unexported fields
}
Terminal is one connected terminal session.
func Dial ¶
func Dial(ctx context.Context, opts DialOptions) (*Terminal, error)
Dial connects a new terminal session. Each invocation generates a random session ID: the endpoint's default session is shared, so a connect must not rejoin a shell an earlier one left. Reconnections within one Terminal keep the ID, which is what recovers the live shell after a transport failure.
func (*Terminal) Run ¶
Run relays the session until it ends: the shell exits, the sandbox closes it, or ctx is done. With a local terminal, the terminal is in raw mode for the session, so keys such as Ctrl+C and Ctrl+D reach the shell. After a transport loss it waits for a keystroke, then reconnects and resumes the same shell; ended input quits that wait too. It returns an error only for a failure, not for the session ending.
type TerminalControl ¶
type TerminalControl interface {
// Size reports the window size.
Size() (cols, rows int, err error)
// MakeRaw puts the terminal in raw mode, returning how to restore it.
MakeRaw() (restore func() error, err error)
// NotifyResize calls resized whenever the window size changes, until ctx
// is done.
NotifyResize(ctx context.Context, resized func())
}
TerminalControl controls the local terminal a session runs in.
func NewOSTerminal ¶
func NewOSTerminal(input, output *os.File) TerminalControl
NewOSTerminal returns a TerminalControl for a terminal read from input and written to output, such as the process's stdin and stdout.
type TransportLostError ¶ added in v1.4.0
type TransportLostError struct {
// contains filtered or unexported fields
}
TransportLostError reports the WebSocket dying without a close frame: the sandbox hibernating pauses the VM and kills the connection, so the server cannot send one.
func (*TransportLostError) Error ¶ added in v1.4.0
func (e *TransportLostError) Error() string
func (*TransportLostError) Unwrap ¶ added in v1.4.0
func (e *TransportLostError) Unwrap() error