Skip to main content
Almost every job you give a sandbox has the same shape: you put something in, it runs, and you take something out. A repository and a prompt go in, and a diff comes out. A spreadsheet goes in, and a report comes out. A test suite goes in, and a test report comes out. The files API is how things move in and out. You send a file’s content as the body of the request and name the path in the address. Because of that, it works for any content, text or binary, up to the size of the sandbox’s disk, and you never have to worry about escaping special characters in a shell command. If the sandbox is asleep, the call wakes it first. These are the five operations:

In, run, out: a sales report

Here is a small but complete round trip. A CSV file of sales and a Python script go into the sandbox. The script adds up the sales per region, and a JSON report comes back out.
1

Start a sandbox

2

Put the data and the script in

response
You do not need to create /work first: missing directories are created for you. If a file already exists at the path, it is replaced. The answer includes the file’s sha256 checksum, so you can confirm that what arrived is exactly what you sent.
3

Run it

response
4

Take the result out

response
With curl, add -o report.json to save the file to your disk instead of printing it.

See what is there

After an agent or a build has run, you often do not know exactly which files it created. List the directory to see what is there:
response
Each entry:
entries
  • A listing covers one level at a time. To look inside a subdirectory, list it separately.
  • type is file, dir or symlink. A symlink also has a target, the path it points to. mtime is the time it was last changed, in Unix seconds, and mode is its permissions in octal.
  • Large directories are cut off at limit entries (10,000 unless you set it). When that happens, truncated is true.
Sometimes you only want to know about a file without downloading it, for example to check that a large download finished correctly. Ask for its details and its checksum instead:
response

A whole folder at once

A project usually has many files. Rather than sending them one by one, pack the folder into a single archive, send it, and unpack it inside the sandbox. That is one request instead of hundreds:
To bring a whole folder back out, do the same in reverse. Pack it inside the sandbox with tar czf /tmp/out.tgz -C /work/app ., then read /tmp/out.tgz (with readBytes in TypeScript, read_bytes in Python, or -o out.tgz with curl).
If your code is in a Git repository, you do not need to upload it at all. Run git clone inside the sandbox: it has git installed and can reach the internet.

Binary files and scripts

Files are passed through byte for byte, so images, archives, SQLite databases and model weights all arrive unchanged. In the SDKs, write accepts either a string or bytes, and readBytes (read_bytes in Python) gives you bytes back. You can also set a file’s permissions while you write it, with mode. For example, 755 makes a script executable, so you can run it directly:
response

Delete

To delete a file, or a directory with everything in it:
response
Deleting a directory requires recursive=true. Without it, Fibre refuses to delete a directory that still has files in it (409 directory_not_empty). This protects you from wiping out a whole tree with a typo.

When a file is not there

Asking for a file that does not exist returns 404 with the code file_not_found. In the SDKs, this is a NotFoundError that you can catch:
response

Errors

These are the errors the files API can return, and what each one means:

Good to know

A few rules to keep in mind:

Clean up

Run commands

Run the code you just put in, and watch its output live.

Create and configure

A sandbox’s size decides how much disk space it has.