Skip to main content
Use sandbox.files to work with files inside a sandbox. Every path argument names a location inside the sandbox; it is the data that moves between the two machines. write(path, data) sends local bytes or text to a sandbox path, and read(path) returns a sandbox file’s content to your program.
write() creates missing parent directories. It replaces the entire file if that path already exists.

Upload and download

Use pathlib.Path to read a local file and send its contents to the sandbox:
After your application creates a result, save it to your computer:
Use read() for text and read_bytes() for binary files. Uploads support up to 4 MiB per call. Text reads support approximately 16 MiB, and binary reads support approximately 12 MiB. Use another transfer method for larger files.

Manage paths

Remove a file or directory with remove():
Removing a directory also removes its contents.

Transfer larger files

For large inputs, download the file from a URL inside the sandbox when possible. You can also send chunks through a command’s standard input. This example uploads a local file without replacing earlier chunks:
Use cat >> for appending; multiple files.write() calls to the same path would overwrite each other. Verify the size or checksum after a transfer. For large outputs, upload from the sandbox to storage you control, then download from there.

Upload a project directory

files.write() is one file per call. To ship a whole directory, pack it locally and unpack it in the sandbox with one command, sending the archive through standard input:
One archive stays within the 4 MiB standard-input limit for most repositories; for a larger project, send the archive with the chunked cat >> pattern above and untar it, or download it inside the sandbox from storage you control. Exclude virtual environments and build artifacts before packing.

Keep or remove files

Files persist between commands and across archive/unarchive. To retain work before deleting the sandbox, download the files or save a durable snapshot. When you are finished: