Sandbox Backup and Restore API Now Available
Cloudflare has introduced backup and restore capabilities to the Sandbox SDK, enabling developers to create point-in-time snapshots of directories and restore them across sessions. This addresses a critical pain point: expensive setup operations like git clone and npm install that can take minutes and must be repeated every time a user starts a new sandbox environment.
Key Capabilities
The new API provides:
- Session persistence — Store backup handles in KV, D1, or Durable Objects to reuse environments across sessions
- Multi-instance support — Fork a single backup across many sandboxes for parallel work
- Named backups — Add human-readable labels for easier management and tracking
- Automatic cleanup — Configure time-to-live (TTL) durations so backups are automatically removed from R2 storage
How It Works
After completing initial setup steps (cloning a repository, installing dependencies, etc.), developers call createBackup() to create a snapshot. The backup handle can be stored and later passed to restoreBackup() to resume work without repeating setup. Backups are stored in R2 and support R2 object lifecycle rules for automatic cleanup.
Getting Started
Developers should consult the backup and restore guide for setup instructions and usage patterns, or the Backups API reference for complete method documentation.