BackendProtocol¶
BackendProtocol
¶
Bases: ABC
Protocol for pluggable memory backends (single, unified).
Backends can store files in different locations (state, filesystem, database, etc.) and provide a uniform interface for file operations.
All file data is represented as dicts with the following structure: { "content": list[str], # Lines of text content "created_at": str, # ISO format timestamp "modified_at": str, # ISO format timestamp }
| METHOD | DESCRIPTION |
|---|---|
ls_info |
List all files in a directory with metadata. |
als_info |
Async version of ls_info. |
read |
Read file content with line numbers. |
aread |
Async version of read. |
grep_raw |
Search for a literal text pattern in files. |
agrep_raw |
Async version of grep_raw. |
glob_info |
Find files matching a glob pattern. |
aglob_info |
Async version of glob_info. |
write |
Write content to a new file in the filesystem, error if file exists. |
awrite |
Async version of write. |
edit |
Perform exact string replacements in an existing file. |
aedit |
Async version of edit. |
upload_files |
Upload multiple files to the sandbox. |
aupload_files |
Async version of upload_files. |
download_files |
Download multiple files from the sandbox. |
adownload_files |
Async version of download_files. |
ls_info
¶
List all files in a directory with metadata.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Absolute path to the directory to list. Must start with '/'.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[FileInfo]
|
List of FileInfo dicts containing file metadata: |
list[FileInfo]
|
|
list[FileInfo]
|
|
list[FileInfo]
|
|
list[FileInfo]
|
|
read
¶
Read file content with line numbers.
| PARAMETER | DESCRIPTION |
|---|---|
file_path
|
Absolute path to the file to read. Must start with '/'.
TYPE:
|
offset
|
Line number to start reading from (0-indexed). Default: 0.
TYPE:
|
limit
|
Maximum number of lines to read. Default: 2000.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
String containing file content formatted with line numbers (cat -n format), |
str
|
starting at line 1. Lines longer than 2000 characters are truncated. |
str
|
Returns an error string if the file doesn't exist or can't be read. |
Note
- Use pagination (offset/limit) for large files to avoid context overflow
- First scan:
read(path, limit=100)to see file structure - Read more:
read(path, offset=100, limit=200)for next section - ALWAYS read a file before editing it
- If file exists but is empty, you'll receive a system reminder warning
aread
async
¶
Async version of read.
grep_raw
¶
Search for a literal text pattern in files.
| PARAMETER | DESCRIPTION |
|---|---|
pattern
|
Literal string to search for (NOT regex). Performs exact substring matching within file content. Example: "TODO" matches any line containing "TODO"
TYPE:
|
path
|
Optional directory path to search in. If None, searches in current working directory. Example: "/workspace/src"
TYPE:
|
glob
|
Optional glob pattern to filter which FILES to search.
Filters by filename/path, not content.
Supports standard glob wildcards:
-
TYPE:
|
Examples:
- "*.py" - only search Python files
- "**/*.txt" - search all .txt files recursively
- "src/**/*.js" - search JS files under src/
- "test[0-9].txt" - search test0.txt, test1.txt, etc.
| RETURNS | DESCRIPTION |
|---|---|
list[GrepMatch] | str
|
On success: list[GrepMatch] with structured results containing: - path: Absolute file path - line: Line number (1-indexed) - text: Full line content containing the match |
list[GrepMatch] | str
|
On error: str with error message (e.g., invalid path, permission denied) |
agrep_raw
async
¶
agrep_raw(
pattern: str, path: str | None = None, glob: str | None = None
) -> list[GrepMatch] | str
Async version of grep_raw.
glob_info
¶
Find files matching a glob pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern
|
Glob pattern with wildcards to match file paths.
Supports standard glob syntax:
-
TYPE:
|
path
|
Base directory to search from. Default: "/" (root). The pattern is applied relative to this path.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[FileInfo]
|
list of FileInfo |
aglob_info
async
¶
Async version of glob_info.
write
¶
edit
¶
Perform exact string replacements in an existing file.
| PARAMETER | DESCRIPTION |
|---|---|
file_path
|
Absolute path to the file to edit. Must start with '/'.
TYPE:
|
old_string
|
Exact string to search for and replace. Must match exactly including whitespace and indentation.
TYPE:
|
new_string
|
String to replace old_string with. Must be different from old_string.
TYPE:
|
replace_all
|
If True, replace all occurrences. If False (default), old_string must be unique in the file or the edit fails.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EditResult
|
EditResult |
aedit
async
¶
Async version of edit.
upload_files
¶
Upload multiple files to the sandbox.
This API is designed to allow developers to use it either directly or by exposing it to LLMs via custom tools.
| PARAMETER | DESCRIPTION |
|---|---|
files
|
List of (path, content) tuples to upload. |
| RETURNS | DESCRIPTION |
|---|---|
list[FileUploadResponse]
|
List of FileUploadResponse objects, one per input file. |
list[FileUploadResponse]
|
Response order matches input order (response[i] for files[i]). |
list[FileUploadResponse]
|
Check the error field to determine success/failure per file. |
Examples:
aupload_files
async
¶
Async version of upload_files.
download_files
¶
Download multiple files from the sandbox.
This API is designed to allow developers to use it either directly or by exposing it to LLMs via custom tools.
| PARAMETER | DESCRIPTION |
|---|---|
paths
|
List of file paths to download. |
| RETURNS | DESCRIPTION |
|---|---|
list[FileDownloadResponse]
|
List of FileDownloadResponse objects, one per input path. |
list[FileDownloadResponse]
|
Response order matches input order (response[i] for paths[i]). |
list[FileDownloadResponse]
|
Check the error field to determine success/failure per file. |
SandboxBackendProtocol
¶
Bases: BackendProtocol
Protocol for sandboxed backends with isolated runtime.
Sandboxed backends run in isolated environments (e.g., separate processes, containers) and communicate via defined interfaces.
| METHOD | DESCRIPTION |
|---|---|
execute |
Execute a command in the process. |
aexecute |
Async version of execute. |
ls_info |
List all files in a directory with metadata. |
als_info |
Async version of ls_info. |
read |
Read file content with line numbers. |
aread |
Async version of read. |
grep_raw |
Search for a literal text pattern in files. |
agrep_raw |
Async version of grep_raw. |
glob_info |
Find files matching a glob pattern. |
aglob_info |
Async version of glob_info. |
write |
Write content to a new file in the filesystem, error if file exists. |
awrite |
Async version of write. |
edit |
Perform exact string replacements in an existing file. |
aedit |
Async version of edit. |
upload_files |
Upload multiple files to the sandbox. |
aupload_files |
Async version of upload_files. |
download_files |
Download multiple files from the sandbox. |
adownload_files |
Async version of download_files. |
execute
¶
execute(command: str) -> ExecuteResponse
Execute a command in the process.
Simplified interface optimized for LLM consumption.
| PARAMETER | DESCRIPTION |
|---|---|
command
|
Full shell command string to execute.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ExecuteResponse
|
ExecuteResponse with combined output, exit code, optional signal, and truncation flag. |
ls_info
¶
List all files in a directory with metadata.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Absolute path to the directory to list. Must start with '/'.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[FileInfo]
|
List of FileInfo dicts containing file metadata: |
list[FileInfo]
|
|
list[FileInfo]
|
|
list[FileInfo]
|
|
list[FileInfo]
|
|
read
¶
Read file content with line numbers.
| PARAMETER | DESCRIPTION |
|---|---|
file_path
|
Absolute path to the file to read. Must start with '/'.
TYPE:
|
offset
|
Line number to start reading from (0-indexed). Default: 0.
TYPE:
|
limit
|
Maximum number of lines to read. Default: 2000.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
String containing file content formatted with line numbers (cat -n format), |
str
|
starting at line 1. Lines longer than 2000 characters are truncated. |
str
|
Returns an error string if the file doesn't exist or can't be read. |
Note
- Use pagination (offset/limit) for large files to avoid context overflow
- First scan:
read(path, limit=100)to see file structure - Read more:
read(path, offset=100, limit=200)for next section - ALWAYS read a file before editing it
- If file exists but is empty, you'll receive a system reminder warning
aread
async
¶
Async version of read.
grep_raw
¶
Search for a literal text pattern in files.
| PARAMETER | DESCRIPTION |
|---|---|
pattern
|
Literal string to search for (NOT regex). Performs exact substring matching within file content. Example: "TODO" matches any line containing "TODO"
TYPE:
|
path
|
Optional directory path to search in. If None, searches in current working directory. Example: "/workspace/src"
TYPE:
|
glob
|
Optional glob pattern to filter which FILES to search.
Filters by filename/path, not content.
Supports standard glob wildcards:
-
TYPE:
|
Examples:
- "*.py" - only search Python files
- "**/*.txt" - search all .txt files recursively
- "src/**/*.js" - search JS files under src/
- "test[0-9].txt" - search test0.txt, test1.txt, etc.
| RETURNS | DESCRIPTION |
|---|---|
list[GrepMatch] | str
|
On success: list[GrepMatch] with structured results containing: - path: Absolute file path - line: Line number (1-indexed) - text: Full line content containing the match |
list[GrepMatch] | str
|
On error: str with error message (e.g., invalid path, permission denied) |
agrep_raw
async
¶
agrep_raw(
pattern: str, path: str | None = None, glob: str | None = None
) -> list[GrepMatch] | str
Async version of grep_raw.
glob_info
¶
Find files matching a glob pattern.
| PARAMETER | DESCRIPTION |
|---|---|
pattern
|
Glob pattern with wildcards to match file paths.
Supports standard glob syntax:
-
TYPE:
|
path
|
Base directory to search from. Default: "/" (root). The pattern is applied relative to this path.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[FileInfo]
|
list of FileInfo |
aglob_info
async
¶
Async version of glob_info.
write
¶
edit
¶
Perform exact string replacements in an existing file.
| PARAMETER | DESCRIPTION |
|---|---|
file_path
|
Absolute path to the file to edit. Must start with '/'.
TYPE:
|
old_string
|
Exact string to search for and replace. Must match exactly including whitespace and indentation.
TYPE:
|
new_string
|
String to replace old_string with. Must be different from old_string.
TYPE:
|
replace_all
|
If True, replace all occurrences. If False (default), old_string must be unique in the file or the edit fails.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EditResult
|
EditResult |
aedit
async
¶
Async version of edit.
upload_files
¶
Upload multiple files to the sandbox.
This API is designed to allow developers to use it either directly or by exposing it to LLMs via custom tools.
| PARAMETER | DESCRIPTION |
|---|---|
files
|
List of (path, content) tuples to upload. |
| RETURNS | DESCRIPTION |
|---|---|
list[FileUploadResponse]
|
List of FileUploadResponse objects, one per input file. |
list[FileUploadResponse]
|
Response order matches input order (response[i] for files[i]). |
list[FileUploadResponse]
|
Check the error field to determine success/failure per file. |
Examples:
aupload_files
async
¶
Async version of upload_files.
download_files
¶
Download multiple files from the sandbox.
This API is designed to allow developers to use it either directly or by exposing it to LLMs via custom tools.
| PARAMETER | DESCRIPTION |
|---|---|
paths
|
List of file paths to download. |
| RETURNS | DESCRIPTION |
|---|---|
list[FileDownloadResponse]
|
List of FileDownloadResponse objects, one per input path. |
list[FileDownloadResponse]
|
Response order matches input order (response[i] for paths[i]). |
list[FileDownloadResponse]
|
Check the error field to determine success/failure per file. |