✦ Sprites 2 Docs

Forking and Reusable Templates

Build an environment once, checkpoint it, and fork it into as many independent Sprites as you need.

On this page

What it is

A checkpoint saves a Sprite’s filesystem and its services at a moment in time. From a checkpoint you can:

  • Restore: roll the same Sprite back to it.
  • Fork: create a brand-new, independent Sprite from it.

Put together, this gives you templates: set up an environment once (install packages, clone code, configure services), checkpoint it, then fork it for each new workload. The same template can be forked thousands of times, for example one fork per job or one per customer. Forks share unchanged storage with the checkpoint, so they’re fast to create, and anything they write afterwards is private to them.

Why it matters: prepare an environment once and reuse it, instead of rebuilding the same setup for every job or customer.

What a checkpoint includes

A checkpoint holds the whole filesystem and the managed service definitions. Everything else belongs to the Sprite, and what happens to it depends on the operation:

SettingRestoreFork
Filesystem and servicesFrom the checkpointFrom the checkpoint
LabelsUnchangedCopied from the source Sprite as it is now
SecretsUnchangedCopied from the source Sprite as it is now
CPU / RAM / disk configUnchangedCopied from the source Sprite as it is now
URL public/private settingsUnchangedNot copied: services start private
Service grants, network policyUnchangedNot copied

“As it is now” means the source’s settings at the time you fork, not at the time of the checkpoint.

Note

A checkpoint captures the filesystem, not memory. Running processes aren’t frozen; services are started fresh after restore or fork.

Step by step: build and use a template

1. Create the template Sprite

ssh my-org@sprites.dev sprite create template

2. Set it up

Do whatever every workload needs. For example:

ssh my-org@sprites.dev sprite exec template --timeout-ms 600000 \
  'git clone https://github.com/acme/agent.git /home/sprite/agent && cd /home/sprite/agent && npm ci'

Register any services the workloads should run (inside the Sprite):

sprite-env service register http --port 8080 --restart always \
  -- /bin/sh -lc 'cd /home/sprite/agent && npm start'

3. Checkpoint it

ssh my-org@sprites.dev checkpoint template v1
# HTTP API
curl -sS -X POST "https://api.sprites.dev/v1/sprites/template/checkpoint" \
  -H "Authorization: Bearer $SPRITES_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"id":"v1","comment":"agent deps installed"}'

Over HTTP, if you leave out the ID, checkpoints are named v1, v2, and so on; over SSH the ID is required. IDs can’t be reused.

4. Fork it

ssh my-org@sprites.dev fork template v1 job-001
# HTTP API
curl -sS -X POST "https://api.sprites.dev/v1/sprites/template/fork" \
  -H "Authorization: Bearer $SPRITES_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"id":"v1","new_sprite_name":"job-001"}'

job-001 is a full, independent Sprite with its own copy of the filesystem, the checkpoint’s services, and the template’s current config, labels and secrets. A new fork starts out stopped and wakes on first use. The stream ends with a fork event containing the new Sprite. If you don’t give a name, it’s called template-fork-RANDOM.

5. Fork many at once

A simple loop creates a fleet:

for i in $(seq -f '%03g' 1 50); do
  curl -sS -X POST "https://api.sprites.dev/v1/sprites/template/fork" \
    -H "Authorization: Bearer $SPRITES_TOKEN" \
    -H "Content-Type: application/json" \
    -d "{\"id\":\"v1\",\"new_sprite_name\":\"job-$i\"}" | tail -n1
done
Tip

If a fork fails with fork_source_busy (409), just retry it. For 429 rate limits, wait briefly and retry.

6. Update the template

When your dependencies change, update the template Sprite and take a new checkpoint (v2). New forks use v2; existing forks are unaffected.

Restoring a Sprite

Checkpoint before anything risky (migrations, upgrades, destructive changes), and roll back if it goes wrong:

ssh my-org@sprites.dev checkpoint dev before-upgrade
# ... do the risky thing ...
ssh my-org@sprites.dev restore dev before-upgrade
# HTTP API
curl -sS -X POST "https://api.sprites.dev/v1/sprites/dev/checkpoint" \
  -H "Authorization: Bearer $SPRITES_TOKEN" \
  -H "Content-Type: application/json" -d '{"id":"before-upgrade"}'
curl -sS -X POST "https://api.sprites.dev/v1/sprites/dev/restore" \
  -H "Authorization: Bearer $SPRITES_TOKEN" \
  -H "Content-Type: application/json" -d '{"id":"before-upgrade"}'
Watch out

Restore replaces the Sprite’s filesystem and services and restarts it. Anything written since the checkpoint is gone.

Inside a Sprite, you can checkpoint yourself:

sprite-env checkpoints create --comment "deps installed"

Managing checkpoints

ssh my-org@sprites.dev checkpoint list dev
ssh my-org@sprites.dev checkpoint delete dev before-upgrade
# HTTP API
curl -sS "https://api.sprites.dev/v1/sprites/dev/checkpoints" \
  -H "Authorization: Bearer $SPRITES_TOKEN"
curl -sS "https://api.sprites.dev/v1/sprites/dev/checkpoints/before-upgrade" \
  -H "Authorization: Bearer $SPRITES_TOKEN"
curl -sS -X DELETE "https://api.sprites.dev/v1/sprites/dev/checkpoints/before-upgrade" \
  -H "Authorization: Bearer $SPRITES_TOKEN"

Forking a whole cluster

If your environment is several Sprites working together (say planner and storage in cluster review-123), fork them all at once:

ssh my-org@sprites.dev cluster fork review-123 review-copy review-fork
# HTTP API
curl -sS -X POST "https://api.sprites.dev/v1/clusters/review-123/fork" \
  -H "Authorization: Bearer $SPRITES_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"target_cluster_id":"review-copy","checkpoint_id":"review-fork"}'

This:

  1. Checkpoints every Sprite in review-123 as review-fork (none may already have a checkpoint with that name).
  2. Forks each into the empty cluster review-copy under the same Sprite name.
  3. Copies the cluster’s service grants, so the Sprites can still talk to each other.

Disposable forks

Add --ephemeral-disk to get a fork whose disk resets to the checkpoint on every cold start. That’s ideal for scratch work you want to throw away and rerun from a clean state:

ssh my-org@sprites.dev fork template v1 scratch --ephemeral-disk

See Durable and Ephemeral Disks for details.

Limits

  • Checkpoint, restore, and fork: 30 each per minute per Sprite.
  • A checkpoint can have 10,000 live forks, or 100 if its Sprite is itself a fork. Deleting forks frees their slots.
  • Fork chains can go 8 levels deep.
  • Sprites with an ephemeral disk can’t be checkpointed, restored, or forked.