Overview
Daytona’s PTY sessions enable:- Interactive terminals - Full terminal emulation with command history
- Real-time I/O - Stream terminal output as it happens
- Terminal control - Resize, manage, and control terminal sessions
- Process management - Monitor and control running processes
Creating PTY Sessions
Basic PTY Session
Create an interactive terminal session:PTY with Custom Environment
PtyCreateOptions & PtyConnectOptions
required
PTY session configuration
Connecting to Existing PTY
Connect to PTY Session
Connect to a previously created PTY session:string
required
ID of the PTY session to connect to
PtyConnectOptions
required
Connection options
Sending Input
Send Text Commands
Send Raw Bytes
string | Uint8Array
required
Input data to send. String for commands/text, Uint8Array for raw control sequences.
Terminal Control
Resize Terminal
Change terminal dimensions:number
required
New number of terminal columns
number
required
New number of terminal rows
Wait for Connection
Ensure the PTY session is ready before sending input:Check Connection Status
Process Management
Wait for Exit
Block until the PTY process terminates:Kill PTY Session
Forcefully terminate the PTY session:Disconnect from PTY
Close the WebSocket connection and clean up:Always disconnect from PTY sessions when done to release resources.
PTY Session Information
List All PTY Sessions
Get Session Details
Interactive Commands Example
Handle Interactive Prompts
Complete Example
Best Practices
Always wait for connection
Always wait for connection
Call
waitForConnection() before sending input to ensure the PTY is ready:Add delays between commands
Add delays between commands
Give commands time to execute before sending the next one:
Clean up resources
Clean up resources
Always disconnect when done:
Handle errors gracefully
Handle errors gracefully
Check connection status and handle errors:
Use Cases
Interactive Shell Sessions
Interactive Shell Sessions
Run interactive shell commands with real-time feedback:
Long-Running Processes
Long-Running Processes
Monitor long-running processes with streaming output:
Terminal Applications
Terminal Applications
Run full terminal applications like vim, htop, etc.:
Automated Testing
Automated Testing
Test CLI applications with automated input:
PTY Handle Properties
Related Resources
Process Execution
Execute commands and code in sandboxes
Computer Use
Desktop automation with GUI interaction