Lifecycle and Persistence
Sprites are persistent, stateful environments that maintain their filesystem and state between runs. This page covers how Sprites manage their lifecycle, including hibernation, persistence, and resource allocation.
Automatic Hibernation
Section titled “Automatic Hibernation”Sprites automatically hibernate when inactive to minimize costs. While hibernated:
- No compute charges - You only pay for storage
- Full state preserved - All files and data intact
- Instant wake - Resume execution immediately on next request
Default Behavior
Section titled “Default Behavior”By default, Sprites hibernate after 30 seconds of inactivity. This timeout is not configurable yet.
Activity Detection
Section titled “Activity Detection”A Sprite is considered active when any of the following are true:
- A command is executing (via
execorconsole) - Data is being written to stdin
- There’s an active TCP connection to the Sprite’s URL
- A detachable session is running
The inactivity timer resets each time activity is detected.
Wake-on-Request
Section titled “Wake-on-Request”When you interact with a hibernated Sprite, it automatically wakes:
# Sprite is hibernated...sprite exec echo "hello" # Sprite wakes, runs command, result returns
# Next command uses already-awake spritesprite exec echo "world" # Fast, no wake neededWake time is typically under a few seconds. Your data, installed packages, and filesystem state are all preserved.
Persistence
Section titled “Persistence”Filesystem
Section titled “Filesystem”Every Sprite has a persistent ext4 filesystem:
- 100GB provisioned storage (current default)
- Standard ext4 compatibility (SQLite, shared memory, all tools work)
- TRIM-friendly billing (pay only for actual data)
How Persistence Works
Section titled “How Persistence Works”What’s Persisted
Section titled “What’s Persisted”| Persisted | Not Persisted |
|---|---|
| All files and directories | Running processes |
| Installed packages | Network connections |
| Environment configurations | In-memory state |
| Git repositories | Temporary /tmp files |
| Databases (SQLite, etc.) | Process PIDs |
Storage Limits
Section titled “Storage Limits”| Metric | Value |
|---|---|
| Provisioned size | 100 GB (current default) |
| Billing | Actual data written |
Storage is TRIM-friendly, meaning you only pay for data actually written to disk. Deleting files reduces your storage costs.
Resource Allocation
Section titled “Resource Allocation”Sprites currently run with a fixed configuration (8 vCPUs, 8192 MB RAM, 100 GB storage). These values are not configurable yet.
Sprite States
Section titled “Sprite States”Sprites have internal lifecycle states such as:
| State | Description |
|---|---|
pending | Sprite is being created |
active | Sprite is running and ready |
hibernating | Sprite is transitioning to hibernation |
hibernated | Sprite is hibernated (no compute) |
waking | Sprite is waking from hibernation |
error | Sprite encountered an error |
These states are not currently exposed in CLI/SDK responses.
Services
Section titled “Services”For processes that need to run continuously and survive Sprite restarts, use Services instead of detachable sessions. Services are managed through the internal API and automatically restart when your Sprite boots.
Services vs Detachable Sessions
Section titled “Services vs Detachable Sessions”| Feature | Services | Detachable Sessions |
|---|---|---|
| Survives Sprite restart | Yes | No |
| Auto-starts on boot | Yes | No |
| Managed via | Internal API (curl-sprite-api) | External CLI/SDK |
| Dependencies | Supported | Not supported |
| Best for | Daemons, dev servers | One-off tasks, builds |
Creating a Service
Section titled “Creating a Service”From inside your Sprite:
# Create a service that auto-starts on bootcurl-sprite-api -X PUT /v1/services/devserver -d '{ "cmd": "npm", "args": ["run", "dev"]}'
# List running servicescurl-sprite-api /v1/services
# Stop a servicecurl-sprite-api -X DELETE /v1/services/devserverSee Services for complete documentation.
Best Practices
Section titled “Best Practices”Optimize for Hibernation
Section titled “Optimize for Hibernation”- Clean up temporary files before long idle periods
- Use SQLite or file-based databases that persist naturally
- Plan for 30s idle hibernation (keep activity running if you need the sprite warm)
Handle Wake Latency
Section titled “Handle Wake Latency”// For latency-sensitive operations, pre-warm the spriteconst sprite = await client.getSprite('my-sprite');
// This exec will wake the sprite if hibernatedawait sprite.exec('true');
// Now the sprite is warm for subsequent operationsconst result = await sprite.exec('your-actual-command');Long-Running Tasks
Section titled “Long-Running Tasks”For tasks that must run for extended periods:
- Use detachable sessions so commands survive disconnection
- Consider services if the process should auto-start on boot
- Consider checkpoints to save progress periodically
# Run in detachable sessionsprite exec -detachable "python long_running_task.py"Related Documentation
Section titled “Related Documentation”- Checkpoints - Save and restore state
- Configuration - All configuration options
- Billing - Pricing details