/v2/ai/sandboxes/{sandbox_id}/files reads and changes files inside a running sandbox. Every call takes an absolute path query parameter.
files get with - as the local path writes to stdout. With curl, percent-encode path when it contains reserved characters.
Common Rules
- Running sandboxes only. The sandbox must be
running(409 sandbox_not_runningotherwise). File calls keep working during the stop’s grace period, so results can be fetched from a sandbox that is ending. - Paths.
pathis absolute, at most 4,096 bytes in UTF-8, and valid UTF-8 once percent-decoded. It is resolved as the sandbox’s kernel resolves it:.,.., and//included. A path containing a NUL byte is422 invalid_path. - Permissions. Calls run as the sandbox’s own user, with its permissions. What that user may not do, or a read-only file system, is
403 permission_denied. - File system refusals. No space, a name too long, a busy file or mount point, a symlink loop, or an I/O error is
422 file_operation_failed, with a fixed text naming the reason. - Size and time. Each call moves at most 64 MiB, within a time budget of about 12 seconds for the whole transfer. A full-size file needs about 5.3 MiB/s between the client and the API to read, and about 6.4 MiB/s to write. Move larger data through Cloud Storage from an exec.
- Not activity. File calls don’t count as activity for
idle_timeout.
Read a File
The response isapplication/octet-stream, and symlinks are followed.
- The length is declared in
Content-Lengthbefore the content. A response shorter than itsContent-Lengthwas cut: the sandbox stopped answering, the file shrank while it was read, or the time budget ran out. Retry. - A file over 64 MiB is
413 file_too_large, before any content is sent. - A directory, device, FIFO, or socket is
409 path_type_mismatch. - Files of at most 1 MiB, including pseudo-files under
/procand/sys, are read whole inside the sandbox first, so their real length is declared. Reading a pseudo-file can use up to 64 MiB of the sandbox’s own memory.
List a Directory
list=true lists the directory at path (a symlink there is followed) as JSON, sorted by name in byte order and paged with page[number] and page[size] (default 20, maximum 100).
.and..aren’t listed; hidden entries are.size_bytesis what the file system reports for the entry itself.modified_atis the sandbox’s own clock.- A directory with more than 100,000 entries is
413 directory_too_large. - Each page is a fresh listing, so entries can move between pages while the directory changes.
- Names that aren’t valid UTF-8 are shown with each invalid byte replaced by U+FFFD. They can’t be addressed through the Files API; use an exec.
- Listing a file is
409 path_type_mismatch.
Write a File
The request body’s raw bytes are written topath, whatever its Content-Type.
- Atomic replace. Readers see the whole old content or the whole new content. A write that fails or is cut off leaves the file exactly as it was.
- Missing parent directories are created with mode
0755once the whole body has arrived. A new file gets0644; a replaced file keeps its permission bits. - A write through a symlink writes the file it points to and keeps the link.
- A write needs permission to write both the file and its directory. A non-root writer becomes the replaced file’s owner; root keeps the old owner.
- An overwrite needs room for both copies until the new one replaces the old. Hard links to the old file keep the old content, and processes holding it open keep reading it.
- Files the sandbox mounts itself (
/etc/hosts,/etc/resolv.conf,/etc/hostname) can’t be replaced this way (422 file_operation_failed). Use an exec. - A directory, device, FIFO, or socket at
path, apathending in/, or a parent that is a file is409 path_type_mismatch. Apathending in.or.., or under/.telnyx, is422 invalid_path. - A declared
Content-Lengthover 64 MiB is413 file_too_largebefore anything reaches the sandbox; a body without one is refused as soon as it passes 64 MiB. - The body must be complete 2 seconds before the time budget ends. A body still arriving then is
408, and the file is unchanged. - A
503after the whole body was sent may have written the file. Retrying writes the same content again, which is harmless.
directory=true and an empty body, the call creates the directory and any missing parents. Trailing slashes are ignored, and a file in the way is 409 path_type_mismatch.
Delete
DELETE removes the file, symlink, or empty directory at path.
- A symlink is removed itself, never its target.
- A non-empty directory needs
recursive=true; otherwise it is409 directory_not_emptyand nothing is removed. A recursive delete never follows symlinks. - Trailing slashes are ignored. A missing path is
404. A parent that is a file is409 path_type_mismatch./, anything under/.telnyx, or apathending in.or..is422 invalid_path. - A recursive delete that runs out of time answers
503, with part of the tree possibly removed; it continues in the sandbox. A retry continues it or, if it has finished meanwhile, answers404. After a503, a404means the delete is done.
Retries
Writes and deletes accept anIdempotency-Key. A retry with the same key, path, flags, and body after the call completed returns the stored answer, and nothing is written or deleted again. A different request with the same key is 422 idempotency_key_reused. A retry that overlaps the first call can repeat the write, or answer 404 for a path the first call deleted.