✦ Sprites 2 Docs

Per-Agent Tokens

Mint a narrow, short-lived token for each agent from one dashboard token, and revoke any of them on its own.

On this page

What it is

Giving every agent your organization’s full-access token is risky: any one of them could stop, delete or read every Sprite you own. Per-agent tokens fix that. You keep one powerful token, and mint a separate child token from it for each agent, CI job or customer.

A child token:

  • can only do what you allow: certain Sprites, certain actions, names with a given prefix, a cap on how many Sprites it may create;
  • expires on its own after the ttl you choose (up to a year), or when its parent expires, whichever comes first;
  • can be revoked by itself, without touching your token or any other agent’s.

Why it matters: if an agent misbehaves or its token leaks, the damage is limited to what that one token allows, for as long as it lives, and you can kill it with one call.

Root tokens and child tokens

There are two kinds of token, and minting connects them:

Root tokenChild token
Created byThe Fly.io dashboard, or POST /tokens without ttlPOST /tokens with ttl, using a parent token
ExpiresNever, unless its policy sets expires_atAfter ttl seconds (at most one year), or when its parent expires, whichever comes first
PermissionsFull access, or narrowed by policy and privilegesEverything its parent has, narrowed further by the request
Shows in GET /tokensYesNo (only its root does)
Revoke withDELETE /tokens/ID (takes all its children with it)POST /tokens/revoke with the token value

All tokens are Fly-format macaroons, beginning fm2_. A child carries every restriction of its parent, so it can never do more than the token that minted it.

Step by step: one token per agent

1. Create a root token in the dashboard

In the Fly.io dashboard, open fly.io/dashboard/ORG/sprites and choose Create Token. This gives you a full-access root token that doesn’t expire. Keep it on your own systems (your orchestrator or backend), never inside an agent.

export SPRITES_TOKEN=fm2_...   # the dashboard token
Tip

You can also create a root token from the API, which is what the dashboard does. Send only description (and optionally policy and privileges), with no ttl:

curl -sS -X POST "https://api.sprites.dev/v1/tokens" \
  -H "Authorization: Bearer $SPRITES_TOKEN" \
  -H "Content-Type: application/json" -d '{"description": "orchestrator"}'

This needs a token that may administer the organization and has no mint_ttl or max_sprites limit, so child tokens can never create roots. See Restricted tokens for the policy fields.

2. Mint a child token for the agent

Say agent 7 should be able to create up to 5 Sprites named agent-7-..., run commands and write files in them, and nothing else. The token should last a day:

curl -sS -X POST "https://api.sprites.dev/v1/tokens" \
  -H "Authorization: Bearer $SPRITES_TOKEN" \
  -H "Content-Type: application/json" -d '{
    "description": "agent-7",
    "ttl": 86400,
    "name_prefix": "agent-7-",
    "max_sprites": 5,
    "sprites": {"*": ["read", "create", "exec", "fs"]}}'

The response looks like this:

{
  "token": "fm2_...",
  "id": "75e9b9c9a806a1b5c97d3de757413de8",
  "description": "agent-7",
  "expires_at": "2026-11-03T17:00:00Z"
}

expires_at is the time ttl seconds from now. If the parent token expires sooner, the child stops working then, even though expires_at shows a later time.

Save token now: it’s shown only once. Keep it somewhere you can find it again, because revoking this one child later needs the token value (see Revoking tokens).

Watch out

The id in the response belongs to the root token the child was minted from, not to the child. DELETE /tokens/ID with that id revokes your root token and every token minted from it. To revoke just this child, use POST /tokens/revoke.

3. Give the token to the agent

The agent uses the child token exactly like any other token:

export SPRITES_TOKEN=fm2_...   # the agent's child token

# Allowed: create a Sprite with the right prefix, and run a command in it
curl -sS -X POST "https://api.sprites.dev/v1/sprites" \
  -H "Authorization: Bearer $SPRITES_TOKEN" \
  -H "Content-Type: application/json" -d '{"name": "agent-7-build"}'

curl -sS -X POST "https://api.sprites.dev/v1/sprites/agent-7-build/exec" \
  -H "Authorization: Bearer $SPRITES_TOKEN" \
  -H "Content-Type: application/json" -d '{"argv": ["echo", "hello"]}'

GET /sprites with this token lists only the Sprites it may read. Anything outside its limits is refused with 403:

# Wrong prefix
curl -sS -X POST "https://api.sprites.dev/v1/sprites" \
  -H "Authorization: Bearer $SPRITES_TOKEN" \
  -H "Content-Type: application/json" -d '{"name": "prod-db"}'
# {"error":"token does not allow this request: sprite_name_prefix"}

# Not one of its actions
curl -sS -X DELETE "https://api.sprites.dev/v1/sprites/agent-7-build" \
  -H "Authorization: Bearer $SPRITES_TOKEN"
# {"error":"token does not allow this request: sprite_action_not_allowed (:destroy)"}

4. Clean up

When the agent is done, its token simply expires: after its ttl, or when an ancestor token expires, if that’s sooner. To end it sooner, revoke it. Delete the agent’s Sprites with your root token, unless you gave the child the destroy action.

What you can restrict

Every field except ttl is optional. Each one you add narrows the child further.

FieldExampleEffect
ttl3600Required. Seconds until the token expires, at most one year (31536000). The token also stops working when its parent does, if that’s sooner.
description"agent-7"A note for yourself.
sprites{"*": ["read", "exec"]}Which Sprites, and which actions on each. Use a Sprite name, or * for every Sprite including ones created later. Without it, the child can act on every Sprite like its parent.
name_prefix"agent-7-"Sprite names must start with this. The way to scope a token that creates Sprites.
max_sprites5How many Sprites it may ever create, forks included. Every attempt counts, even one that failed or a Sprite since deleted.
labels["team-a"]Sprites must carry every listed label. A token with this limit can’t create Sprites.
services{"web": [8080]}The URL services it may reach, and on which ports. [] allows every port.
connectors{"CONNECTION_ID": []}The API gateway connections it may use, and which endpoints. [] allows every endpoint.
privileges["usage.read"]Limit it to usage data (usage.read) or to reaching web services (service.proxy).
mint_ttl3600Let this child mint its own children, each lasting at most this many seconds. The default 0 means it can’t mint.

A child can’t be wider than its parent. Asking for more than the parent allows, such as an action the parent doesn’t have, returns 400.

Actions

These are the actions you can list for each Sprite in sprites:

ActionAllows
readSeeing the Sprite, its logs and its discovery info
createCreating new Sprites (give it on *, usually with name_prefix)
execRunning commands
fsWriting files through the API
consoleInteractive console sessions
start, stopWaking and stopping the Sprite
destroyDeleting the Sprite
checkpoint, restore, forkCheckpoints, restores and forks
servicesManaging its services
mailboxDelivering messages to its mailbox
updateChanging its settings, including network policy and URL settings. Changing labels also needs organization-admin rights, so a child limited to particular Sprites can’t assign new labels.
automationsManaging its automations. Writing one also needs start, stop and exec.
proxyReaching its web services through its URLs (read alone doesn’t)
Note

A Sprite named in sprites is matched by its ID, which is looked up when the token is minted. The Sprite must already exist (otherwise you get 400 unknown sprite). If you delete it and create a new one with the same name, the old token doesn’t cover the new one.

Common recipes

Run commands in one existing Sprite for an hour. The agent can’t create, stop or delete anything:

curl -sS -X POST "https://api.sprites.dev/v1/tokens" \
  -H "Authorization: Bearer $SPRITES_TOKEN" \
  -H "Content-Type: application/json" -d '{
    "description": "review-bot", "ttl": 3600,
    "sprites": {"review-sandbox": ["read", "exec", "fs"]}}'

A sandbox agent that manages its own Sprites. It creates, wakes, stops and deletes only Sprites named sandbox-42-..., at most 10 of them:

curl -sS -X POST "https://api.sprites.dev/v1/tokens" \
  -H "Authorization: Bearer $SPRITES_TOKEN" \
  -H "Content-Type: application/json" -d '{
    "description": "sandbox-42", "ttl": 604800,
    "name_prefix": "sandbox-42-", "max_sprites": 10,
    "sprites": {"*": ["read", "create", "start", "stop", "destroy", "exec", "fs"]}}'

A usage dashboard token. It reads usage data and can’t see any Sprites (GET /sprites returns an empty list):

curl -sS -X POST "https://api.sprites.dev/v1/tokens" \
  -H "Authorization: Bearer $SPRITES_TOKEN" \
  -H "Content-Type: application/json" -d '{
    "description": "grafana", "ttl": 31536000, "privileges": ["usage.read"]}'

Mint tokens for a batch of agents. Save each token to a file as you go, so you can hand it out and revoke it later:

mkdir -p tokens && chmod 700 tokens
for n in 1 2 3; do
  curl -sS -X POST "https://api.sprites.dev/v1/tokens" \
    -H "Authorization: Bearer $SPRITES_TOKEN" \
    -H "Content-Type: application/json" \
    -d "{\"description\":\"agent-$n\",\"ttl\":86400,\"name_prefix\":\"agent-$n-\",\"max_sprites\":3,
         \"sprites\":{\"*\":[\"read\",\"create\",\"exec\",\"fs\"]}}" \
    | jq -r '.token' > "tokens/agent-$n"
done

Letting a child mint its own children

An orchestrator agent might need to hand out tokens to sub-agents itself. Give its token mint_ttl:

curl -sS -X POST "https://api.sprites.dev/v1/tokens" \
  -H "Authorization: Bearer $SPRITES_TOKEN" \
  -H "Content-Type: application/json" -d '{
    "description": "orchestrator", "ttl": 86400, "mint_ttl": 3600,
    "name_prefix": "job-", "sprites": {"*": ["read", "create", "exec"]}}'

The orchestrator can now mint children of its own, using its token as the parent:

curl -sS -X POST "https://api.sprites.dev/v1/tokens" \
  -H "Authorization: Bearer $ORCHESTRATOR_TOKEN" \
  -H "Content-Type: application/json" -d '{
    "description": "job-17 worker", "ttl": 1800,
    "sprites": {"job-17": ["read", "exec"]}}'

The rules:

  • Each grandchild’s ttl must be no more than the orchestrator’s mint_ttl. Asking for more returns 403 ... token_mint_ttl.
  • A grandchild keeps all of the orchestrator’s limits (here, the job- prefix) and can only narrow them. Asking for an action the orchestrator doesn’t have returns 400 the child token would allow more than its parent.
  • A token with max_sprites can’t mint at all, because each child would get a fresh allowance. Put the create limit on the tokens at the bottom of the tree instead.
  • A child can never create a root token, whatever it’s allowed to do.

Revoking tokens

There are two ways to revoke, and both need a token that may administer the organization, such as your dashboard token. A child narrowed with sprites, name_prefix, labels or privileges can’t revoke tokens, list them, or create root tokens.

Revoke one child. Send the child’s token value. Its parent and its siblings keep working:

curl -sS -X POST "https://api.sprites.dev/v1/tokens/revoke" \
  -H "Authorization: Bearer $SPRITES_TOKEN" \
  -H "Content-Type: application/json" -d '{"token": "fm2_..."}'

This returns 204. The child then gets 401 authentication failed, after a short delay on some API servers while their caches are invalidated (see below). Copies narrowed from it offline die with it.

Watch out

Revoking a child does not revoke children it minted itself with mint_ttl. They keep working until they expire: after their own ttl, or when an ancestor expires, whichever comes first. To stop them sooner, revoke each one, or delete the root token. This is one reason to keep mint_ttl short.

Revoke a root token and its whole family. List the root tokens to find the id, then delete it:

curl -sS "https://api.sprites.dev/v1/tokens" -H "Authorization: Bearer $SPRITES_TOKEN"

curl -sS -X DELETE "https://api.sprites.dev/v1/tokens/TOKEN_ID" \
  -H "Authorization: Bearer $SPRITES_TOKEN"

This revokes the root and every token minted from it, at any depth. The API runs on several servers, and each one caches token checks. A revocation reaches the other servers when those caches are invalidated, so another server may accept a revoked token for a short time.

Tip

GET /tokens lists only root tokens; children never appear in it. If you want to be able to revoke agents one at a time, keep each child token (or at least know where it is) when you mint it. Otherwise your only options are waiting for it to expire or revoking the whole root.

For an easy kill switch for a group of agents, create a separate root token for that group in the dashboard and mint their children from it. Deleting that root ends all of them without affecting anything else.

Narrowing a token without the API

Anyone holding a token can make a narrower copy of it offline by adding restrictions with a Fly macaroon library (Go, Elixir). Such a copy can only ever do less, and it dies with the token it came from. It can’t be revoked on its own, though, so use POST /tokens when you need that. The restriction formats are described in the API’s OpenAPI document at https://api.sprites.dev/v1/openapi.json.

Errors

StatusMessageWhat it means
400ttl must be a positive number of seconds, at most a yearttl is missing or too long. Any narrowing field, such as name_prefix or sprites, makes the request a child request, which needs ttl.
400the child token would allow more than its parent (...)You asked for something the parent token doesn’t have
400unknown action "..." / unknown sprite "..."A typo in an action, or a Sprite in sprites that doesn’t exist
403token does not allow this request: token_mint_ttlThe parent has no mint_ttl, or ttl is longer than it
403a token with a create limit cannot mint childrenThe parent has max_sprites
403this token cannot choose sprite labelsA token with a labels limit tried to create a Sprite
403token does not allow this request: sprite_name_prefixThe Sprite name doesn’t start with the token’s prefix
403token does not allow this request: sprite_action_not_allowed (:stop)The action isn’t in the token’s sprites list
401token expiredThe token, or one of the tokens it was minted from, has expired
401authentication failedThe token was revoked, or isn’t a valid token