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
Response
response
/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
Response
response
4
Take the result out
Response
Response
response
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
Response
response
entries
- A listing covers one level at a time. To look inside a subdirectory, list it separately.
typeisfile,dirorsymlink. A symlink also has atarget, the path it points to.mtimeis the time it was last changed, in Unix seconds, andmodeis its permissions in octal.- Large directories are cut off at
limitentries (10,000 unless you set it). When that happens,truncatedistrue.
Response
Response
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: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).
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
Response
response
Delete
To delete a file, or a directory with everything in it:Response
Response
response
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 returns404 with the code file_not_found. In the SDKs, this is a
NotFoundError that you can catch:
Response
Response
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
Related
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.