Prerequisites
Before you begin, make sure you have:- Active sandbox - A running sandbox (see Creating Sandboxes)
- WebSocket library - For Python:
pip install websockets(for JavaScript, WebSocket is built-in) - Understanding of async/await - Familiarity with asynchronous programming patterns
- Terminal access - Basic understanding of terminal/command-line operations
Overview
The WebSocket terminal is ideal for:- Interactive command-line tools and REPLs
- Real-time monitoring of long-running processes
- Terminal applications that require PTY support
- Building terminal UIs or dashboards
- Debugging and troubleshooting
The WebSocket terminal requires the
websockets library for Python. Install it with: pip install websocketsConnecting to Terminal
Connect to the terminal using theterminal resource:
- Python
- JavaScript
Sending Input
Send commands and input to the terminal:- Python
- JavaScript
Receiving Output
Receive terminal output in real-time using async iteration:- Python
- JavaScript
Resizing Terminal
Resize the terminal window to match your display:- Python
- JavaScript
Complete Example
Here’s a complete example that demonstrates interactive terminal usage:- Python
- JavaScript
Message Types
The terminal sends different message types:-
output: Terminal output data -
exit: Process exit notification
Error Handling
Handle connection errors and timeouts:- Python
- JavaScript
Best Practices
API Reference
Python SDK
sandbox.terminal.connect(*, timeout=30)- Connect to terminal WebSocketsandbox.terminal.send_input(ws, data)- Send input to terminalsandbox.terminal.resize(ws, cols, rows)- Resize terminal windowsandbox.terminal.iter_output(ws)- Async iterator for terminal messages
JavaScript SDK
sandbox.terminal.connect()- Connect to terminal WebSocketsandbox.terminal.sendInput(ws, data)- Send input to terminalsandbox.terminal.resize(ws, cols, rows)- Resize terminal windowsandbox.terminal.output(ws)- Async iterator for terminal messages
API Endpoint
- WebSocket:
/terminal- Connect to interactive terminal - Message Types:
input,resize,output,exit
Related
- Running Commands - Execute shell commands synchronously
- Background Commands - Run commands in background
- SDK: sandbox.terminal.connect() - Python SDK method
- CLI Terminal - Terminal access from CLI
Next Steps
- Learn about Running Commands for synchronous execution
- Explore Background Commands for non-blocking tasks
- Review Code Execution for programmatic execution

