Blaxel Volumes are currently in private preview. Please contact us if you would like to get access before the public release date.
Blaxel Volumes provide persistent storage that survives sandbox destruction and recreation, enabling stateful development environments and data retention across VM lifecycle events. While Blaxel automatically snapshots the full state of a sandbox at scale down and stores it in a warm storage for ultra-fast boot times, volumes offer a more cost-effective solution to persist files for weeks to years.

Create & delete a volume

To create a standalone volume, you must provide a unique name and specify its size in megabytes (MB). This volume exists independently of any sandbox.
import { SandboxInstance, VolumeInstance } from "@blaxel/core";

const volume = await VolumeInstance.create({
  name: "my-volume",
  size: 2048,          // in MB
  region: "us-pdx-1"   // if not specified, Blaxel will choose a default region
});
To delete a volume:
await VolumeInstance.delete("my-volume");
To list existing volumes:
const volumes = await VolumeInstance.list()

Attach volume to a sandbox

At this time, you can only attach one volume to a sandbox. A volume can also only be attached to one sandbox at a time.
To use a volume, attach it when you create a sandbox by passing an array of volume configurations to the volumes property. Each configuration must include the name of the volume to attach and the mountPath where it will be accessible inside the sandbox’s filesystem. The mount path will override the existing content of a directory.
const sandbox = await SandboxInstance.create({
  name: "my-sandbox",
  image: "blaxel/prod-nextjs:latest",
  memory: 4096,
  region: "us-pdx-1",     // Must be the same region as the created volume
  volumes: [{
    name: "my-volume"     // Must match the name of the created volume
    mountPath: "/app"     // Directory inside the sandbox
    readOnly: false       // Set to true to prevent writes
  }],
  // ... other sandbox properties
});
Any files written to the /app directory within this sandbox will be stored on my-volume and will persist even if this sandbox is deleted. At this time, you cannot detach a volume from a sandbox.