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:readscope (for read operations) andsessions:writescope (for write operations) - A session in
runningstate
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.).
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:
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.