Volumes are currently in private beta.
If you’d like access, please reach out to us at support@e2b.dev.
Volume SDK methods covered below are meant for working with a volume when it is not mounted to any sandbox.
Quickstart
Create a volume and mount it to a sandbox. Any file written under the mount path is persisted in the volume and remains available to future sandboxes.Managing volumes
TheVolume class exposes lifecycle operations for creating, listing, inspecting, and destroying volumes.
Create a volume
Create a new named volume. Volume names can only contain letters, numbers, and hyphens.Connect to an existing volume
Useconnect() to get a handle to an existing volume by its ID. This is how you reach a volume that was created in a previous session.
List volumes
List all volumes in your team.Get volume info
Fetch metadata for a single volume by ID.Destroy a volume
Permanently delete a volume and all of its contents. This cannot be undone.Mounting volumes to a sandbox
PassvolumeMounts / volume_mounts to Sandbox.create() to attach one or more volumes when the sandbox starts. Keys are the mount paths inside the sandbox; values are either a Volume object or the volume name.
Reading and writing files
When a volume is not mounted, you can interact with its contents directly through theVolume instance methods.
Read a file
Read the contents of a file from a volume.Write a file
Write content to a file in the volume. Parent directories must already exist — usemakeDir() / make_dir() if they don’t.
Create a directory
Create a directory in the volume. Passforce: true / force=True to create any missing parent directories.
List directory contents
List the entries (files and subdirectories) at a path in the volume.Remove files or directories
Remove a file, or remove a directory by passing therecursive option.
File and directory metadata
Inspect files and directories withgetInfo() / get_info(), check for existence with exists(), or change ownership and permissions with updateMetadata() / update_metadata().
Get information about a file
Retrieve metadata such as size, mode, owner, and timestamps for a file.Get information about a directory
The samegetInfo() / get_info() method also works for directories.
Check if a path exists
Useexists() to test whether a file or directory is present without throwing if it isn’t.
Update metadata
Change a file or directory’s user ID, group ID, or permission mode.Uploading data from the local filesystem
To move data from your machine into a volume, read the file locally and pass the contents towriteFile() / write_file().
Upload a single file
Upload a directory
Iterate over the files in the directory and upload each one. The SDK does not currently provide a recursive upload helper, so nested directories need to be walked explicitly.Downloading data to the local filesystem
Read the file from the volume withreadFile() / read_file() and write the contents to disk.