Skip to main content
Serverless Sandboxes is in public preview.
Use file operations to share data between your local environment and a sandbox. You can read files from a sandbox, write files to it, or mount local files and directories into it. For example, you can write a Python script to a sandbox, run it, and read the output file back to your local environment. You can also mount a directory of training data into a sandbox for a machine learning job.
Choose the right file access methodMount files or directories when you want the sandbox to access local data without copying it.Read and write files when you want to transfer smaller files between your local environment and the sandbox, or when you want to save sandbox output locally.

Write a file to the sandbox

Write a file to the sandbox when you need to upload inputs your sandbox code uses, such as scripts, configs, or data files. Transfer a file from your local environment to the sandbox using the Sandbox.write_file() method.
See the Sandbox class reference documentation for a full list of parameters and options for Sandbox.write_file().

Read a file from the sandbox

Save a file from the sandbox to your local environment using the Sandbox.read_file() method.
See the Sandbox class reference documentation for a full list of parameters and options for Sandbox.read_file().

Mount a file or directory

Use mounted files to provide local files to the sandbox at creation time. Unlike Sandbox.write_file(), which transfers files to a running sandbox, mounted files are available as soon as the sandbox starts. Mounted files appear in the sandbox at the path you specify.
Mounted files are read-only in the sandbox. If you need to modify files in the sandbox, use Sandbox.write_file() instead.
The following code snippet mounts the local files train.py and requirements.txt to the sandbox root directory. The sandbox installs dependencies from requirements.txt and then runs train.py.