Skip to main content
Every session has a full Linux filesystem. The files API lets you read, write, list, search, upload, and download files without opening a terminal or WebSocket. This guide covers the patterns for each operation. For the complete endpoint specifications, see the file operation pages under Sessions.

When to use this

  • You are reading agent output (generated code, logs, artifacts) from a script or coding agent
  • You want to seed a session with files before sending a prompt
  • You need to download build artifacts or generated assets from a session
  • You are searching session files for specific patterns

Prerequisites

  • An API key with sessions:read scope (for read operations) and sessions:write scope (for write operations)
  • A session in running state

List files

GET /api/sessions/{id}/files returns files and directories under a given path. By default it walks up to 3 levels deep and excludes build artifacts (node_modules, .git, __pycache__, etc.).
Useful parameters:

Read a file

GET /api/sessions/{id}/files/read returns the content of a single file as a string:

Write a file

POST /api/sessions/{id}/files/write creates or overwrites a file. Parent directories are created automatically:
Write config files, seed data, or .env files before sending the first prompt so the agent has the context it needs from the start.

Upload a file

POST /api/sessions/{id}/files/upload accepts a multipart file upload for binary or large files:

Download a file

GET /api/sessions/{id}/files/download returns the raw file content as a binary stream:

Search file content

GET /api/sessions/{id}/files/search searches file contents with a text query:

Create a directory

POST /api/sessions/{id}/files/mkdir creates a directory (and any missing parents):

Delete a file

DELETE /api/sessions/{id}/files removes a file or directory:

Rename or move a file

POST /api/sessions/{id}/files/rename moves or renames a file:

Path constraints

All paths must resolve under /home/user or the session’s workspace_path. Attempting to read or write outside the sandbox returns 400:

Next steps

Manage sessions at scale

Lifecycle management, polling, and error recovery.

Handle long-running prompts

Cancel, rewind, and replay prompt history.

Files API reference

Full endpoint specification for all file operations.

Terminal WebSocket

Interactive shell access for running commands directly.