Skip to content

PtyClient

Source: src/services/pty.ts

PtyClient(transport: Leap0Transport)

Creates and manages PTY sessions for interactive terminals.

  • Leap0Error: If API calls or response validation fail.
async list(sandbox: SandboxRef, options: RequestOptions = {}): Promise<PtySession[]>

Lists PTY sessions for a sandbox.

  • sandbox: Sandbox ID or sandbox-like object.
  • options: Optional request settings such as timeout and query params.
  • The PTY sessions in the sandbox.
async create(sandbox: SandboxRef, params: CreatePtySessionParams = {}, options: RequestOptions = {}): Promise<PtySession>

Creates a PTY session.

  • sandbox: Sandbox ID or sandbox-like object.
  • params: PTY session creation parameters.
  • options: Optional request settings such as timeout and query params.
  • The created PTY session.
async get(sandbox: SandboxRef, sessionId: string, options: RequestOptions = {}): Promise<PtySession>

Fetches a PTY session by ID.

  • sandbox: Sandbox ID or sandbox-like object.
  • sessionId: PTY session identifier.
  • options: Optional request settings such as timeout and query params.
  • The requested PTY session.
async delete(sandbox: SandboxRef, sessionId: string, options: RequestOptions = {}): Promise<void>

Deletes a PTY session.

  • sandbox: Sandbox ID or sandbox-like object.
  • sessionId: PTY session identifier.
  • options: Optional request settings such as timeout and query params.
async resize(sandbox: SandboxRef, sessionId: string, cols: number, rows: number, options: RequestOptions = {}): Promise<PtySession>

Resizes an existing PTY session.

  • sandbox: Sandbox ID or sandbox-like object.
  • sessionId: PTY session identifier.
  • cols: Terminal column count.
  • rows: Terminal row count.
  • options: Optional request settings such as timeout and query params.
  • The updated PTY session.
websocketUrl(sandbox: SandboxRef, sessionId: string): string

Returns the websocket URL for a PTY session.

  • sandbox: Sandbox ID or sandbox-like object.
  • sessionId: PTY session identifier.
  • The PTY websocket URL.
websocketHeaders(): Record<string, string>

Returns auth headers to use when opening the PTY websocket manually.

  • Headers required for PTY websocket authentication.
connect(sandbox: SandboxRef, sessionId: string): PtyConnection

Opens a websocket connection for an existing PTY session.

  • sandbox: Sandbox ID or sandbox-like object.
  • sessionId: PTY session identifier.
  • The PTY websocket connection wrapper.
  • Leap0WebSocketError: If subsequent websocket reads fail.
const pty = sandbox.pty.connect("shell");
pty.send("ls\n");
const output = await pty.recv();