> ## Documentation Index
> Fetch the complete documentation index at: https://developers.telnyx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Files

> Read, write, list, and delete files inside a running sandbox, with atomic writes and files of up to 64 MiB per request.

`/v2/ai/sandboxes/{sandbox_id}/files` reads and changes files inside a running sandbox. Every call takes an absolute `path` query parameter.

| Operation | Request | Success |
| - | - | - |
| Read a file | `GET …/files?path=/app/out.txt` | `200`, raw bytes |
| List a directory | `GET …/files?path=/app&list=true` | `200`, JSON page |
| Write a file | `PUT …/files?path=/app/in.txt` with the bytes as body | `201` created, `200` replaced |
| Create a directory | `PUT …/files?path=/app/data&directory=true`, empty body | `201` created, `200` already there |
| Delete | `DELETE …/files?path=/app/out.txt` | `204` |
| Delete a directory tree | `DELETE …/files?path=/app/data&recursive=true` | `204` |

```bash CLI theme={null}
telnyx-edge sandbox-gpu files put "$SANDBOX_ID" config.yaml /app/config.yaml
telnyx-edge sandbox-gpu files get "$SANDBOX_ID" /app/results.json results.json
telnyx-edge sandbox-gpu files ls "$SANDBOX_ID" /app
telnyx-edge sandbox-gpu files mkdir "$SANDBOX_ID" /app/data
telnyx-edge sandbox-gpu files rm -r "$SANDBOX_ID" /app/tmp
```

```bash curl theme={null}
BASE="https://api.telnyx.com/v2/ai/sandboxes/$SANDBOX_ID/files"
AUTH="Authorization: Bearer $TELNYX_API_KEY"

curl -sS -H "$AUTH" -X PUT --data-binary @config.yaml "$BASE?path=/app/config.yaml"
curl -sS -H "$AUTH" "$BASE?path=/app/results.json" -o results.json
curl -sS -H "$AUTH" -G "$BASE" --data-urlencode "path=/app" \
  --data-urlencode "list=true" --data-urlencode "page[size]=100"
curl -sS -H "$AUTH" -X DELETE "$BASE?path=/app/tmp&recursive=true"
```

The CLI retries a download that was cut short and replaces the local file only once the whole file has arrived; `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_running` otherwise). File calls keep working during the stop's grace period, so results can be fetched from a sandbox that is ending.
* **Paths.** `path` is 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 is `422 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](https://developers.telnyx.com/docs/cloud-storage/overview.md) from an [exec](https://developers.telnyx.com/docs/gpu-sandboxes/execs.md).
* **Not activity.** File calls don't count as activity for `idle_timeout`.

## Read a File

The response is `application/octet-stream`, and symlinks are followed.

* The length is declared in `Content-Length` before the content. **A response shorter than its `Content-Length` was 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 `/proc` and `/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).

```json theme={null}
{
  "data": [
    { "name": "config.yaml", "path": "/app/config.yaml", "type": "file", "size_bytes": 412, "modified_at": "2026-11-13T10:15:02Z" },
    { "name": "data", "path": "/app/data", "type": "directory", "size_bytes": 4096, "modified_at": "2026-11-13T10:14:40Z" }
  ],
  "meta": { "page_number": 1, "page_size": 20, "total_pages": 1, "total_results": 2 }
}
```

| `type` | Entry |
| - | - |
| `file` | A regular file. |
| `directory` | A directory. |
| `symlink` | A symbolic link, listed with its own size and time, never followed. |
| `other` | A device, FIFO, or socket. |

* `.` and `..` aren't listed; hidden entries are.
* `size_bytes` is what the file system reports for the entry itself. `modified_at` is 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 to `path`, 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 `0755` once the whole body has arrived. A new file gets `0644`; 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`, a `path` ending in `/`, or a parent that is a file is `409 path_type_mismatch`. A `path` ending in `.` or `..`, or under `/.telnyx`, is `422 invalid_path`.
* A declared `Content-Length` over 64 MiB is `413 file_too_large` before 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 `503` after the whole body was sent may have written the file.** Retrying writes the same content again, which is harmless.

With `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 is `409 directory_not_empty` and nothing is removed. A recursive delete never follows symlinks.
* Trailing slashes are ignored. A missing path is `404`. A parent that is a file is `409 path_type_mismatch`. `/`, anything under `/.telnyx`, or a `path` ending in `.` or `..` is `422 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, answers `404`. After a `503`, a `404` means the delete is done.

## Retries

Writes and deletes accept an `Idempotency-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.
