The Sandbox SDK now supports PTY (pseudo-terminal) passthrough, enabling browser-based terminal UIs to connect to sandbox shells via WebSocket.
sandbox.terminal(request)
The new terminal() method proxies a WebSocket upgrade to the container’s PTY endpoint, with output buffering for replay on reconnect.
JavaScript
// Worker: proxy WebSocket to container terminalreturn sandbox.terminal(request, { cols: 80, rows: 24 });TypeScript
// Worker: proxy WebSocket to container terminalreturn sandbox.terminal(request, { cols: 80, rows: 24 });
Multiple terminals per sandbox
Each session can have its own terminal with an isolated working directory and environment, so users can run separate shells side-by-side in the same container.
JavaScript
// Multiple isolated terminals in the same sandboxconst dev = await sandbox.getSession("dev");return dev.terminal(request);TypeScript
// Multiple isolated terminals in the same sandboxconst dev = await sandbox.getSession("dev");return dev.terminal(request);
xterm.js addon
The new @cloudflare/sandbox/xterm export provides a SandboxAddon for xterm.js with automatic reconnection (exponential backoff + jitter), buffered output replay, and resize forwarding.
JavaScript
import { SandboxAddon } from "@cloudflare/sandbox/xterm";const addon = new SandboxAddon({getWebSocketUrl: ({ sandboxId, origin }) =>`${origin}/ws/terminal?id=${sandboxId}`,onStateChange: (state, error) => updateUI(state),});terminal.loadAddon(addon);addon.connect({ sandboxId: "my-sandbox" });TypeScript
import { SandboxAddon } from "@cloudflare/sandbox/xterm";const addon = new SandboxAddon({getWebSocketUrl: ({ sandboxId, origin }) =>`${origin}/ws/terminal?id=${sandboxId}`,onStateChange: (state, error) => updateUI(state),});terminal.loadAddon(addon);addon.connect({ sandboxId: "my-sandbox" });
Upgrade
To update to the latest version:
npm i @cloudflare/sandbox@latestSource: Cloudflare
Latest Posts
- (Updated) Realtime voice is now available in M365 Copilot Chat and M365 Copilot [MC1085684]
![(Updated) Realtime voice is now available in M365 Copilot Chat and M365 Copilot [MC1085684] 2 pexels ekamelev 927500](data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==)
- (Updated) Microsoft 365 Copilot Chat: New ways to include files and emails in prompts [MC1139489]
![(Updated) Microsoft 365 Copilot Chat: New ways to include files and emails in prompts [MC1139489] 3 pexels minan1398 1006098](data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==)
- (Updated) Microsoft 365 Copilot: New ways to include files and emails as part of prompts in chat web scope [MC1139488]
![(Updated) Microsoft 365 Copilot: New ways to include files and emails as part of prompts in chat web scope [MC1139488] 4 pexels googledeepmind 25626509](data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==)
- (Updated) Microsoft SharePoint: Update to News web part “See all” experience [MC1182713]
![(Updated) Microsoft SharePoint: Update to News web part “See all” experience [MC1182713] 5 pexels googledeepmind 17486101](data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==)

![(Updated) Realtime voice is now available in M365 Copilot Chat and M365 Copilot [MC1085684] 2 pexels ekamelev 927500](https://mwpro.co.uk/wp-content/uploads/2024/08/pexels-ekamelev-927500-150x150.webp)
![(Updated) Microsoft 365 Copilot Chat: New ways to include files and emails in prompts [MC1139489] 3 pexels minan1398 1006098](https://mwpro.co.uk/wp-content/uploads/2024/08/pexels-minan1398-1006098-150x150.webp)
![(Updated) Microsoft 365 Copilot: New ways to include files and emails as part of prompts in chat web scope [MC1139488] 4 pexels googledeepmind 25626509](https://mwpro.co.uk/wp-content/uploads/2025/06/pexels-googledeepmind-25626509-150x150.webp)
![(Updated) Microsoft SharePoint: Update to News web part “See all” experience [MC1182713] 5 pexels googledeepmind 17486101](https://mwpro.co.uk/wp-content/uploads/2025/06/pexels-googledeepmind-17486101-150x150.webp)
![(Updated) Microsoft SharePoint: Update to News web part “See all” experience [MC1182713] 7 (Updated) Microsoft SharePoint: Update to News web part “See all” experience [MC1182713]](https://mwpro.co.uk/wp-content/uploads/2025/06/pexels-googledeepmind-17486101-96x96.webp)