# Files

Each sandbox has its own disk. Upload input files, let your code or agent work, download the results – everything else disappears with the sandbox.

## Upload and download

**Python**

```
sb.files.write("/home/user/data.csv", open("data.csv", "rb").read())   # bytes or text
png = sb.files.read("/home/user/chart.png")                           # bytes
text = sb.files.read_text("/home/user/report.md")
print(sb.files.list("/home/user"))
sb.files.mkdir("/home/user/out")
sb.files.remove("/home/user/tmp", recursive=True)
```

**curl**

```
# upload (raw bytes; parent directories are created)
curl -s -X PUT "https://sandbox.wbx.cz/v1/sandboxes/SB_ID/files?path=/home/user/data.csv" \
  -H "Authorization: Bearer YOUR_API_KEY" --data-binary @data.csv

# download
curl -s "https://sandbox.wbx.cz/v1/sandboxes/SB_ID/files?path=/home/user/chart.png" \
  -H "Authorization: Bearer YOUR_API_KEY" -o chart.png
```

Missing parent directories are created when you write a file.

## All file endpoints

| Endpoint | What it does |
| --- | --- |
| GET / PUT / DELETE /v1/sandboxes/{id}/files?path= | Download, upload or delete a file. |
| GET /v1/sandboxes/{id}/fs/list?path=&depth=1 | List a directory (name, type, size, mode, modification time); `depth` up to 5. |
| GET /v1/sandboxes/{id}/fs/stat?path= | Information about one file or directory. |
| POST /v1/sandboxes/{id}/fs/mkdir | `{"path": "/home/user/out", "parents": true}` |
| POST /v1/sandboxes/{id}/fs/move | `{"from": "…", "to": "…", "overwrite": false}` |
| POST /v1/sandboxes/{id}/fs/remove | `{"path": "…"}` – directories are removed with their contents; `"recursive": false` removes only an empty one. |
| GET /v1/sandboxes/{id}/fs/watch?path=&recursive=false | NDJSON stream of changes (create, write, remove, rename). |

## Keeping files

A destroyed sandbox loses its disk. To keep files between sessions, let the sandbox [fall asleep](https://sandbox.wbx.cz/docs/sandboxes/sleep.md) instead – its files are kept for 7 days. For results of longer work use a [background job](https://sandbox.wbx.cz/docs/jobs.md): its result files stay available for 7 days after the sandbox is gone, and other jobs can [use them as inputs](https://sandbox.wbx.cz/docs/jobs/inputs.md).

Source: https://sandbox.wbx.cz/docs/sandboxes/files
