Quick Use
pip install modalvolume = modal.Volume.from_name("my-vol", create_if_missing=True)- Mount in any Function or Sandbox via
volumes={"/path": volume}, call.commit()to checkpoint
Intro
Modal Volumes give your Modal Functions and Sandboxes persistent storage that survives across runs. Mount as a regular Linux filesystem, share between Functions and Sandboxes, version checkpoints with .commit(). Best for: caching pip packages and model weights, ML training datasets, agent workspaces that span multiple runs. Works with: Modal SDK. Setup time: 1 minute.
Create + mount
import modal
app = modal.App("ml-pipeline")
volume = modal.Volume.from_name("model-cache", create_if_missing=True)
@app.function(volumes={"/cache": volume})
def download_model():
import huggingface_hub
huggingface_hub.snapshot_download(
"meta-llama/Llama-3-8B",
cache_dir="/cache",
)
volume.commit() # checkpoint to durable storageCache pip packages across runs
pip_cache = modal.Volume.from_name("pip-cache", create_if_missing=True)
image = modal.Image.debian_slim().run_commands(
"pip install --target=/pip-cache transformers torch",
).env({"PYTHONPATH": "/pip-cache"})
@app.function(image=image, volumes={"/pip-cache": pip_cache})
def train(): ...Cold starts drop from minutes to seconds because packages are already on the volume.
Share data between Function and Sandbox
data_vol = modal.Volume.from_name("ingest", create_if_missing=True)
@app.function(volumes={"/data": data_vol})
def ingest():
download_csv_files("/data/raw/")
data_vol.commit()
@app.function(volumes={"/data": data_vol})
def analyze():
data_vol.reload() # pick up the latest committed snapshot
return run_analysis("/data/raw/")Use as agent workspace
workspace = modal.Volume.from_name("agent-runs", create_if_missing=True)
# Each agent run gets its own subdirectory
sb = modal.Sandbox.create(
image=image,
volumes={"/work": workspace},
workdir="/work/run-{run_id}",
)
sb.exec("python", "agent.py")
workspace.commit() # save the workLater runs read the workspace history; the agent has long-term memory across sessions.
FAQ
Q: How is Volume different from S3? A: Volumes mount as a Linux filesystem (no S3 API translation). Faster random reads, integrated with Modal's image cache. For purely archival or external access, S3 is still the right choice.
Q: Are Volumes versioned?
A: Yes — every .commit() creates a new version. You can read prior versions with volume.reload(commit_id=...). Useful for rollbacks and reproducibility.
Q: How big can a Volume be? A: Practically unlimited. The hot tier is fast (NVMe-class); colder data is offloaded transparently. You're billed for storage used, but the limit isn't hard.
Source & Thanks
Built by Modal. Commercial product with free tier.
modal.com/docs — Volumes documentation