Skip to main content
sbx.PTY is the *PTY sub-object available on every Sandbox instance. It provides methods to create interactive terminal sessions, send input, resize, stream output, and kill sessions.

sbx.PTY.Create()

Create a new PTY session. The sandbox spawns an interactive shell and returns a *PtyHandle.
If no PtySize is provided, the default 80x24 is used:
PtySize
default:"PtySize{Cols: 80, Rows: 24}"
Initial terminal dimensions (optional variadic argument).
Returns (*PtyHandle, error)

PtyHandle

PtyHandle is returned by PTY.Create(). It exposes the full session lifecycle.

handle.PID

Type int — the process ID of the shell process backing the PTY.

handle.SendInput()

Forward keystrokes or text to the shell.
[]byte
required
Raw bytes to send to the PTY stdin.
Returns error

handle.SetSize()

Change the remote terminal dimensions. Fires SIGWINCH inside so ncurses apps redraw.
int
required
Number of columns.
int
required
Number of rows.
Returns error

handle.Stream()

Returns a read-only channel that receives output data from the PTY as []byte chunks. The channel is closed when the PTY session ends or the context is canceled.
The stream uses Server-Sent Events (SSE). Output chunks are base64-decoded automatically. Returns (<-chan []byte, error)

handle.Kill()

Terminate the PTY session (SIGKILL to the process group).
Returns error

PtySize


Example: interactive PTY session