Conway

PTY Sessions

Create and manage pseudo-terminal sessions in sandboxes.

Create PTY Session

POST /v1/sandboxes/:id/pty

Create a new PTY (pseudo-terminal) session for interactive programs like Python REPL, vim, or shell sessions.

Path Parameters

ParameterTypeRequiredDescription
idstringYesThe full sandbox ID

Request Body

ParameterTypeRequiredDescription
commandstringYesCommand to run (e.g., bash, python3, vim)
colsnumberNoTerminal width in columns. Defaults to 80.
rowsnumberNoTerminal height in rows. Defaults to 24.

Example

curl -X POST https://api.conway.tech/v1/sandboxes/abc123def456/pty \
  -H "Authorization: Bearer your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "command": "python3",
    "cols": 120,
    "rows": 40
  }'
const response = await fetch(
  "https://api.conway.tech/v1/sandboxes/abc123def456/pty",
  {
    method: "POST",
    headers: {
      Authorization: "Bearer your-api-key",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      command: "python3",
      cols: 120,
      rows: 40,
    }),
  }
);

Response

{
  "session_id": "pty_789xyz",
  "sandbox_id": "abc123def456",
  "command": "python3",
  "cols": 120,
  "rows": 40,
  "state": "running",
  "created_at": "2026-01-30T12:00:00Z"
}

Use Cases

  • Interactive REPLs: Python, Node.js, Ruby interpreters
  • Text editors: vim, nano, emacs
  • Interactive CLIs: AWS CLI, kubectl, docker
  • Shell sessions: Long-running bash sessions with state

Write to PTY

POST /v1/sandboxes/:id/pty/:sessionId/write

Send input to a PTY session.

Path Parameters

ParameterTypeRequiredDescription
idstringYesThe full sandbox ID
sessionIdstringYesThe PTY session ID

Request Body

ParameterTypeRequiredDescription
inputstringYesInput to send. Use \n for Enter, \x03 for Ctrl+C.

Example

curl -X POST https://api.conway.tech/v1/sandboxes/abc123def456/pty/pty_789xyz/write \
  -H "Authorization: Bearer your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "input": "print(\"Hello, World!\")\n"
  }'
const response = await fetch(
  "https://api.conway.tech/v1/sandboxes/abc123def456/pty/pty_789xyz/write",
  {
    method: "POST",
    headers: {
      Authorization: "Bearer your-api-key",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      input: 'print("Hello, World!")\n',
    }),
  }
);

Response

{
  "success": true,
  "bytes_written": 24,
  "session_id": "pty_789xyz"
}

Special Characters

CharacterEscape SequenceDescription
Enter\nSubmit command
Tab\tTab completion
Ctrl+C\x03Interrupt/cancel
Ctrl+D\x04EOF/exit
Ctrl+Z\x1aSuspend process
Arrow Up\x1b[APrevious command
Arrow Down\x1b[BNext command

Read from PTY

GET /v1/sandboxes/:id/pty/:sessionId/read

Read output from a PTY session.

Path Parameters

ParameterTypeRequiredDescription
idstringYesThe full sandbox ID
sessionIdstringYesThe PTY session ID

Query Parameters

ParameterTypeRequiredDescription
fullbooleanNoIf true, return full scrollback buffer. Default: false (current screen only).

Example

curl "https://api.conway.tech/v1/sandboxes/abc123def456/pty/pty_789xyz/read?full=false" \
  -H "Authorization: Bearer your-api-key"
const response = await fetch(
  "https://api.conway.tech/v1/sandboxes/abc123def456/pty/pty_789xyz/read?full=false",
  {
    headers: { Authorization: "Bearer your-api-key" },
  }
);

Response

{
  "output": "Python 3.11.0 (main, Oct 24 2022, 18:26:48)\n>>> print(\"Hello, World!\")\nHello, World!\n>>> ",
  "state": "running",
  "session_id": "pty_789xyz",
  "cols": 120,
  "rows": 40
}

Tips

  • Poll this endpoint periodically to get updated output
  • Use full=true to retrieve scrollback history for long sessions
  • Check state to detect if the process has exited

Resize PTY

POST /v1/sandboxes/:id/pty/:sessionId/resize

Resize a PTY session's terminal dimensions.

Path Parameters

ParameterTypeRequiredDescription
idstringYesThe full sandbox ID
sessionIdstringYesThe PTY session ID

Request Body

ParameterTypeRequiredDescription
colsnumberYesNew terminal width in columns
rowsnumberYesNew terminal height in rows

Example

curl -X POST https://api.conway.tech/v1/sandboxes/abc123def456/pty/pty_789xyz/resize \
  -H "Authorization: Bearer your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "cols": 200,
    "rows": 50
  }'
const response = await fetch(
  "https://api.conway.tech/v1/sandboxes/abc123def456/pty/pty_789xyz/resize",
  {
    method: "POST",
    headers: {
      Authorization: "Bearer your-api-key",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ cols: 200, rows: 50 }),
  }
);

Response

{
  "success": true,
  "session_id": "pty_789xyz",
  "cols": 200,
  "rows": 50
}

Close PTY Session

DELETE /v1/sandboxes/:id/pty/:sessionId

Close a PTY session and terminate the running process.

Path Parameters

ParameterTypeRequiredDescription
idstringYesThe full sandbox ID
sessionIdstringYesThe PTY session ID to close

Example

curl -X DELETE https://api.conway.tech/v1/sandboxes/abc123def456/pty/pty_789xyz \
  -H "Authorization: Bearer your-api-key"
await fetch(
  "https://api.conway.tech/v1/sandboxes/abc123def456/pty/pty_789xyz",
  {
    method: "DELETE",
    headers: { Authorization: "Bearer your-api-key" },
  }
);

Response

{
  "success": true,
  "session_id": "pty_789xyz",
  "state": "exited"
}

List PTY Sessions

GET /v1/sandboxes/:id/pty

List all active PTY sessions for a sandbox.

Path Parameters

ParameterTypeRequiredDescription
idstringYesThe full sandbox ID

Example

curl https://api.conway.tech/v1/sandboxes/abc123def456/pty \
  -H "Authorization: Bearer your-api-key"
const response = await fetch(
  "https://api.conway.tech/v1/sandboxes/abc123def456/pty",
  {
    headers: { Authorization: "Bearer your-api-key" },
  }
);

Response

{
  "sandbox_id": "abc123def456",
  "sessions": [
    {
      "session_id": "pty_789xyz",
      "command": "python3",
      "state": "running",
      "cols": 120,
      "rows": 40,
      "created_at": "2026-01-30T12:00:00Z"
    },
    {
      "session_id": "pty_abc123",
      "command": "bash",
      "state": "running",
      "cols": 80,
      "rows": 24,
      "created_at": "2026-01-30T12:05:00Z"
    }
  ],
  "total": 2
}