Skip to main content
The PTY (pseudo-terminal) API provides interactive terminal sessions with full TTY support, enabling complex terminal interactions, real-time input/output, and terminal control.

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:
Or using the process API:
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:
PTY Result:

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

Call waitForConnection() before sending input to ensure the PTY is ready:
Give commands time to execute before sending the next one:
Always disconnect when done:
Check connection status and handle errors:

Use Cases

Run interactive shell commands with real-time feedback:
Monitor long-running processes with streaming output:
Run full terminal applications like vim, htop, etc.:
Test CLI applications with automated input:

PTY Handle Properties

Process Execution

Execute commands and code in sandboxes

Computer Use

Desktop automation with GUI interaction