← Back
Cloudflare
Cloudflare Sandbox SDK adds PTY terminal support for browser-based shell access

Interactive Browser Terminals Now Available

The Sandbox SDK has been enhanced with PTY (pseudo-terminal) passthrough capabilities, enabling developers to build browser-based terminal interfaces that directly connect to sandbox container shells via WebSocket.

Key Features

New sandbox.terminal() method: Proxies WebSocket upgrades to the container's PTY endpoint with built-in output buffering for seamless reconnection playback.

Multiple isolated terminals: Each session can maintain its own terminal with independent working directories and environments, allowing users to run separate shells side-by-side within the same container.

xterm.js integration: A new @cloudflare/sandbox/xterm addon provides:

  • Automatic reconnection with exponential backoff and jitter
  • Buffered output replay on reconnect
  • Automatic resize forwarding to match terminal dimensions

Getting Started

Update to the latest version with:

npm i @cloudflare/sandbox@latest

The simple API allows you to expose a terminal from your Worker:

return sandbox.terminal(request, { cols: 80, rows: 24 });

For xterm.js users, the new addon handles connection management and state updates automatically, reducing boilerplate code for interactive terminal UIs.