Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

API Specification — Terminal Runtime Layer

Protocol and endpoint definitions for communication between the agent and the runtime layer.

Transport

ModeWhen to UseDetails
Unix socketLocal, same machineImplemented. Default path: /tmp/trl.sock (or TRL_SOCKET_PATH). Fast, secure (file perms).
HTTPRemote, Docker, multi-hostPlanned. Would bind to 127.0.0.1:<port> with token auth.
Stdin/StdoutCLI testing, pipingPlanned. One-shot mode. Read JSON from stdin, write JSON to stdout.

Protocol

All messages are JSON. Every request has a method and optional params. Every response has ok (bool), optional data, and optional error.

Request Format

{
  "id": "req-001",
  "method": "session.create",
  "params": {
    "shell": "/bin/zsh",
    "env": {"MY_VAR": "value"},
    "working_dir": "/tmp/sandbox"
  }
}

Response Format (Success)

{
  "id": "req-001",
  "ok": true,
  "data": {
    "session_id": "s-a1b2c3",
    "created_at": "2026-02-13T12:00:00Z"
  }
}

Response Format (Error)

{
  "id": "req-001",
  "ok": false,
  "error": {
    "code": "SESSION_NOT_FOUND",
    "message": "No session with id 's-xyz'"
  }
}

Methods

Session Management

session.create

Create a new terminal session.

Params:

FieldTypeRequiredDefaultDescription
shellstringNo/bin/shShell to use for the session
envobjectNo{}Additional environment variables
working_dirstringNo/tmpInitial working directory
namestringNonullHuman-readable session label
timeout_sintNo0 (none)Default command timeout for this session

Response data: session_id, shell, working_dir, state, created_at


session.list

List all active sessions. Params: None.


session.info

Get details about a specific session. Params: session_id (required).


session.destroy

Terminate and clean up a session. Params: session_id (required), force (optional bool).


Command Execution

exec.run

Execute a command in a session (buffered mode). Waits for completion.

Params: session_id, command, timeout_s, stdin, env

Response data: stdout, stderr, exit_code, duration_ms, timed_out


exec.stream (planned)

Execute with real-time output streaming. Would return stream_id, then push chunks. Not yet implemented.


exec.cancel (planned)

Cancel a running command. Params: session_id, signal (optional). Not yet implemented.


System

system.ping

Health check. Response: uptime_s, version.

system.stats

Runtime statistics: active_sessions, total_commands_run, uptime_s, memory_rss_bytes.


Error Codes

CodeMeaning
SESSION_NOT_FOUNDNo session with given ID
SESSION_BUSYSession already running a command
COMMAND_TIMEOUTCommand exceeded timeout
COMMAND_FAILEDCommand exited with non-zero
INVALID_PARAMSMissing or malformed parameters
INTERNAL_ERRORUnexpected runtime error
AUTH_FAILEDInvalid or missing authentication token

Authentication (HTTP mode)

When running over HTTP, requests must include:

Authorization: Bearer <token>

The token is set via TRL_AUTH_TOKEN environment variable when starting the runtime. Unix socket mode relies on filesystem permissions instead.