sandboxconnect

package
v1.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func (t *Terminal) Run(ctx context.Context) error

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL