SPAWNBOX

Fleets

Run Spawnbox on more than one host: a primary, workers and edges, failover, draining and autoscaling.

You can run sandboxes on more than one host. One host is the primary. The other hosts are workers.

  • Your clients send all requests to the primary. They use the same URL and the same API keys as before.
  • The primary also runs sandboxes. For each new sandbox, it selects a host. It selects a host with a warm VM first, then the host with the most free memory.
  • The primary sends each request for a sandbox to the host of the sandbox.
  • You make tenants, keys, secrets and templates only on the primary. The primary copies them to the workers. Each worker builds the templates itself.
  • Workers send their events and usage to the primary. GET /v1/events and GET /v1/usage on the primary show the data of all hosts.

The hosts talk on two ports, with HTTPS and certificates on the two sides (mutual TLS):

Port On Function
7443 Primary Workers join and send reports
7444 Each worker The primary sends requests for sandboxes

WARNING: Use a private network between the hosts. Do not open ports 7443 and 7444 to the internet.

Step 1: Prepare the hosts

  1. Install Spawnbox on each host. Do the steps in Getting started on each host.

  2. Make sure that the hosts can connect to each other on ports 7443 and 7444. On AWS, add an inbound rule to the security group of the hosts: type All TCP, source the same security group.

  3. Find the private IP address of each host. On each host, type:

    hostname -I

    In these steps, the primary is 10.0.0.1 and the worker is 10.0.0.2. Use your addresses.

  4. To move sandboxes between hosts (refer to Drain a worker), all hosts must have the same backend, the same files and the same CPU model. Copy /opt/spawnbox/vmlinux and /opt/spawnbox/rootfs.ext4 from the primary to each worker. Do not build these files again on each host. Each build gives different bytes. Copy to a new file name, then use sudo mv to replace the old file. Do not write into the old file: paused sandboxes and builds use it. Then restart the worker. Install the same Spawnbox release on all hosts.

  5. You can mix Firecracker hosts and gVisor hosts in one fleet. Sandboxes of a microvm-only tenant go only to Firecracker hosts. Refer to Firecracker or gVisor.

Step 2: Make the primary

Type these commands on the primary.

  1. Open the settings file:

    sudo nano /etc/spawnbox/spawnbox.env
  2. Add --fleet-listen 10.0.0.1:7443 to the SPAWNBOX_ARGS line.

  3. Save the file and restart the service:

    sudo systemctl restart spawnbox
  4. Make a join token. The token is valid for one hour and for one worker only:

    curl -s -H "$A" -X POST http://127.0.0.1:8080/v1/nodes/tokens

    The response has token and ca_sha256. Keep them for step 3.

Step 3: Add a worker

Type these commands on the worker.

  1. Open the settings file:

    sudo nano /etc/spawnbox/spawnbox.env
  2. Replace the SPAWNBOX_ARGS line with these lines. Use your addresses, and the token and ca_sha256 from step 2. Use the same --preview-url as the primary.

    SPAWNBOX_ARGS="--preview-url http://{label}.localhost:8081 --primary https://10.0.0.1:7443 --node-listen 10.0.0.2:7444 --advertise https://10.0.0.2:7444 --primary-ca-sha256 CA_SHA256"
    SPAWNBOX_JOIN_TOKEN=TOKEN
  3. Save the file and restart the service:

    sudo systemctl restart spawnbox
  4. Make sure that the worker joined:

    sudo journalctl -u spawnbox -n 20 | grep "fleet worker"

    The log shows fleet worker nod_....

  5. On the primary, make sure that the worker is ready:

    curl -s -H "$A" http://127.0.0.1:8080/v1/nodes

A worker uses the token only one time. After this, it uses its certificate in /var/lib/spawnbox/fleet/worker/.

NOTE: A worker does not take API requests from clients. It does not use --listen and --preview-listen.

What occurs when a host stops

  • No report from a worker for 15 seconds. The primary puts no new sandboxes on it.
  • No report for 30 seconds. The state of the worker becomes down. Requests for its sandboxes give 503 node_unreachable. Try again later. When the worker comes back, its sandboxes operate again.
  • A worker restarts. Its running sandboxes are deleted, as on one host. Its paused sandboxes stay, and running persistent sandboxes pause first (--shutdown-pause-s). To keep the running sandboxes, drain the worker before you restart it.
  • Persistent sandboxes on a down worker stay on that worker until Spawnbox knows that their VMs are stopped. Refer to Fence lost hosts.

Fence lost hosts

A down worker can still run its VMs: maybe only its network to the primary is cut. If Spawnbox started a persistent sandbox again on a different host, two copies of its programs could run. So a persistent sandbox of a down or removed worker becomes cold only when one of these proves that its VM is stopped:

  • The worker comes back and reports the sandbox stopped or missing.

  • The fleet uses --self-fence, and --fence-after-s plus --fence-margin-s passed since the last report of the worker.

  • The autoscaler hook removed the machine of the worker.

  • You tell the primary that the host is off:

    curl -s -H "$A" -X POST http://127.0.0.1:8080/v1/nodes/NODE_ID:fenced \
      -d '{"reason":"machine powered off"}'

    Do this only after you stop the machine. The primary records the node.fenced event with your key.

DELETE /v1/nodes/{id} and the down state alone prove nothing. Until there is a proof, requests for these sandboxes give 503 node_unreachable.

Self-fencing. A worker with --self-fence that cannot reach the primary for --fence-after-s seconds (default 60) stops all its persistent VMs. Each one becomes cold on the worker, with a sandbox.fenced event. Other sandboxes continue to run. Add --self-fence to every worker: each worker tells the primary if it uses the flag, and the primary waits for a time only for the workers that do.

SPAWNBOX_ARGS="... --primary https://10.0.0.1:7443 --self-fence --fence-after-s 60"

On the primary, --fence-margin-s (default 30) is the time to add for clocks and slow hosts. The worker counts from when it sent its last heartbeat that got an answer, and the primary from when it got that heartbeat, so the worker always fences first. Keep the margin above 10 seconds: a worker can take a few seconds to see the fence time and stop its VMs.

When the server process dies. VMs run in their own cgroups, outside the spawn-api process and its systemd service, so they would keep running after a crash. The time proofs above need them stopped. So spawn-api serve starts a small guard process, spawn-api guard, before any VM. When the server process ends in any way, also with kill -9, the out-of-memory killer or a crash, the guard kills all the VMs of the host within about a second. A normal stop with SIGTERM stops the VMs first and then tells the guard to exit. The guard is in its own cgroup, /sys/fs/cgroup/spawnbox-guard, and ignores SIGINT and SIGTERM, so stopping the service does not stop it too early. If the guard cannot start, a server with --self-fence, --fleet-listen or --database-url does not start. If the guard stops while such a server runs, the server kills its VMs and exits.

Generations. Each cold start adds 1 to the generation of the sandbox. A host runs a sandbox only for the generation that the primary gave it. When a worker comes back with an older copy, the primary tells it to delete that copy (sandbox.fenced with the reason stale_generation). The old copy never resumes.

Where a cold sandbox starts. Calls for a cold or starting sandbox go to the primary, also through an edge. The primary checks the key, starts the sandbox on a host with its template build and room, then forwards the call. Previews start it on the primary. If the start on a worker fails before the worker got it, the primary starts it on itself.

Keep the API up when the primary stops

With one primary, the API stops when the primary stops. To prevent this, run two or more primaries on one Postgres database. One primary is the leader and serves the API. The others are standbys: they wait and do not listen on any port. When the leader stops, a standby becomes the leader in about 15 seconds. The new leader serves at once and builds its own copy of the base template in the background; until that is ready, new sandboxes start on workers.

  1. Make a Postgres 15 (or later) database, for example on Amazon RDS.

  2. Copy /var/lib/spawnbox/secrets.key from the primary to the same path on each standby host. All primaries must use the same key.

  3. On each primary, add the database to /etc/spawnbox/spawnbox.env:

    SPAWNBOX_DATABASE_URL=postgres://spawnbox:PASSWORD@db.internal:5432/spawnbox

    Also add --fleet-listen to SPAWNBOX_ARGS, as in step 2.

  4. To keep the data of an existing primary, add --import-sqlite /var/lib/spawnbox/spawnbox.db on that primary for its first start. It copies the data only when the database is empty.

  5. Start the primaries. The first one to start becomes the leader.

  6. Put a load balancer in front of the primaries, with a health check on GET /healthz. Only the leader passes it.

  7. On workers and edges, give each primary in --primary, separated by commas:

    --primary https://10.0.0.1:7443,https://10.0.0.5:7443

The leader keeps the fleet CA, the egress CA and the browser session key in the database, encrypted with the secrets key. A new leader uses the same ones, so workers and browser sessions continue to operate.

When a standby becomes the leader:

  • Sandboxes on workers continue to run.
  • Sandboxes that ran on the old leader are lost. Paused sandboxes whose files were on the old leader are marked failed.
  • Volumes whose file was on the old leader are lost.
  • Persistent sandboxes of the old leader become cold after --fence-after-s plus --fence-margin-s. Until then, requests for them give 409. The next request starts them on the new leader, or on a worker. If that host lacks their build, it builds their template spec again first. Refer to Upgrades and old builds.
  • If the leader cannot reach the database for 6 seconds, or another primary took its lease, it stops taking requests, kills all its VMs and exits, before its lease ends. So two primaries never serve at the same time.

To use TLS with a certificate check, give the CA of the database in --database-ca-file. Without it, the connection uses TLS if the server offers it, but accepts any certificate.

Drain a worker and move its sandboxes

Do these steps before you update, restart or remove a worker. Type the commands on the primary.

  1. Drain the worker. The primary puts no new sandboxes on it, and moves its sandboxes to other hosts:

    curl -s -H "$A" -d '{"migrate":true}' http://127.0.0.1:8080/v1/nodes/NODE_ID:drain

    To stop only new sandboxes, and not move the sandboxes, use {"migrate":false}.

  2. Wait until the worker has no sandboxes. sandboxes in this response must be 0. To remove the worker, also wait until volumes is 0:

    curl -s -H "$A" http://127.0.0.1:8080/v1/nodes/NODE_ID

    When the moves are complete, the event node.drained shows the number of sandboxes that moved and that did not move. The primary also moves the volumes of the worker. One drain call moves what it can once. If something did not move, call :drain again. Only one move pass runs on a worker at a time: while one runs, GET /v1/nodes/NODE_ID shows "drain_running": true, and another :drain call starts nothing and answers "drain_pass": "already_running". A pass ends if the primary stops. A standby that takes over keeps the worker drained but does not start a new pass, so call :drain again.

  3. Do your work on the worker.

  4. Let the worker take new sandboxes again:

    curl -s -H "$A" -d '{}' http://127.0.0.1:8080/v1/nodes/NODE_ID:undrain

With the CLI, spawnbox nodes drain NODE_ID --wait does steps 1 and 2. Until the worker holds no sandboxes and no volumes, it calls :drain again when no pass runs and a minute has passed since its last call, so it also restarts the drain after a standby takes over. It waits out errors, such as the API being away during that takeover, and exits with 1 after --timeout seconds (default 1800), or at once if someone undrains the worker. spawnbox nodes ls shows SANDBOXES, VOLUMES and the VERSION of each worker, and spawnbox nodes undrain NODE_ID does step 4.

Persistent sandboxes in a drain. A persistent sandbox cannot move with its memory: its snapshot works only on the host that made it. So the drain stops it on the worker and makes it cold, as a cold start needs:

  1. The worker writes the data of its volumes to disk, stops the VM and records sandbox.cold with the reason drained. Requests for the sandbox wait during this time; a request that was already in the sandbox fails, so try it again.
  2. The primary copies its volumes to another host with the same backend.
  3. A sandbox that was running starts again at once on another host, at the next generation. A sandbox that was paused stays cold and starts on its next request.

node.drained shows persistent_cold (stopped this way), restarted and restart_failed. One that could not start again stays cold and starts on its next request.

Its ID, env, secrets, network rules, volumes and published ports stay the same. Its processes and its files outside volumes are gone, as in any cold start. The old copy on the worker can never run again: a copy with an older generation is deleted.

If no other ready host has the backend of one of its volumes, the drain does not stop the sandbox. It keeps running on the worker, node.drained counts it in failed, and the log of the primary says which volume cannot leave. Add a host with that backend and call :drain again, or restart the worker in place: its paused persistent sandboxes stay.

You can also move one sandbox. The primary selects the host with the most free memory. To select a host, add "node" with a node ID or "primary":

curl -s -H "$A" -d '{"node":"primary"}' http://127.0.0.1:8080/v1/sandboxes/SANDBOX_ID:migrate

What occurs during a move:

  • The primary pauses the sandbox, copies its memory and disk to the other host, and starts it there. On the test servers, this takes 3 to 7 seconds.
  • The sandbox keeps its ID, files, processes, preview URLs and secrets. Clients use the same URLs.
  • During the move, requests for the sandbox wait. They continue when the move is complete.
  • A running sandbox stays running. A paused sandbox stays paused.
  • If the move fails, the sandbox stays on its first host and continues. The response is an error with "retryable": true.
  • The event sandbox.migrated shows from, to, was_running and duration_ms.

NOTE: You cannot drain the primary. Sandboxes move only between hosts with the same backend, kernel, base disk, Firecracker or runsc, egress CA and CPU model. Each worker uses the egress CA of the primary for this reason.

Volumes on more than one host

The data of a volume is on one host. This host is the home of the volume. node in GET /v1/volumes/{name} shows the home. null is the primary.

  • The primary puts a sandbox that mounts a volume on the home of the volume.

  • If the home is full or draining, the primary copies the volume to a different host. It does this only if no sandbox uses the volume, or only cold sandboxes use it.

  • If the volumes of a sandbox are on different hosts, the primary copies them to one host first.

  • When a sandbox moves, its volumes move with it. A sandbox can move only if it is the only sandbox that uses its volumes. If not, the response is 409.

  • A volume moves only between hosts with the same backend.

  • If the home of a volume is down, sandboxes cannot use the volume. The response is 503 node_unreachable, or 503 volume_unavailable when a cold sandbox starts. Try again when the host comes back.

  • When you drain a worker with {"migrate":true}, the primary also copies the volumes of the worker to other hosts, also those of persistent sandboxes that the drain made cold. The event node.drained shows volumes_moved and volumes_failed.

CAUTION: Before you remove a worker, drain it. Make sure that GET /v1/volumes shows no volume with the node of the worker. If you remove a worker that is the home of a volume, you lose the data of the volume.

Add an edge

An edge is a front door for your clients. It runs no sandboxes. It sends each request to the correct host:

  • Commands, terminals, files, git:clone and preview URLs go directly to the host of the sandbox. The primary is not in the path.
  • All other requests go to the primary.

If the primary stops, commands, terminals, files and previews of running sandboxes continue to operate through the edge. Other requests fail with 503 until the primary starts again.

The edge does not need KVM or root. You can run it on the primary, on a worker or on a different small host.

  1. On the primary, make a join token, as in step 3.

  2. On the edge host, type:

    sudo /opt/spawnbox/bin/spawn-api edge \
      --primary https://PRIMARY_PRIVATE_IP:7443 \
      --join-token TOKEN \
      --primary-ca-sha256 CA_SHA256 \
      --data-dir /var/lib/spawnbox-edge \
      --listen 0.0.0.0:443 \
      --tls-cert /etc/spawnbox/api.crt --tls-key /etc/spawnbox/api.key \
      --preview-listen 0.0.0.0:8443 \
      --preview-tls-cert /etc/spawnbox/preview.crt \
      --preview-tls-key /etc/spawnbox/preview.key

    You can also set the token in SPAWNBOX_JOIN_TOKEN. Without the TLS options, the edge uses plain HTTP. The edge keeps its certificate in the data directory. When it starts again, it does not need a token.

  3. Point your clients and your preview domain to the edge. Use the same API keys as before. The host that gets the request checks the key.

You can run more than one edge. Put them behind a TCP load balancer.

The edge gets the list of hosts and sandboxes from the primary each second. Thus:

  • For approximately 1 s after a sandbox moves, a request can go to the old host.
  • If a worker starts again while the primary is stopped, the worker refuses requests from edges until the primary is available.

To remove an edge, use DELETE /v1/nodes/NODE_ID. After approximately 5 s, the edge refuses all requests with 403.

Remove a worker

  1. On the primary, type:

    curl -s -H "$A" -X DELETE http://127.0.0.1:8080/v1/nodes/NODE_ID

    The primary marks the sandboxes of the worker as deleted. It does not send requests to the worker again.

  2. On the worker, stop the service:

    sudo systemctl stop spawnbox

To add the same host again, remove /var/lib/spawnbox/fleet/worker/ on the worker. Then do step 3 with a new token.

Upgrade a fleet without loss

Upgrade one host at a time, so that the fleet keeps serving. Upgrade the primaries first: a primary accepts workers of the release before it, and only a primary of this release or later can stop persistent sandboxes for a drain. Back up the database first; refer to step 4.

  1. Standby primaries. On each standby, type the install command again. A standby serves nothing, so this loses nothing.

  2. The leader. Type the install command on the leader. It restarts the service in place:

    • On SIGTERM, running persistent sandboxes pause (--shutdown-pause-s, default 30). Ones that do not pause in time become cold. Plain sandboxes that run on the leader are deleted, as on one host; paused ones stay.
    • The leader keeps its lease while it stops. If it starts again within about 15 seconds, it is the leader again and its paused persistent sandboxes resume with their memory on their next request.
    • If a standby takes over instead, the API moves to it within about 15 seconds, and the persistent sandboxes of the old leader become cold after --fence-after-s plus --fence-margin-s. Refer to Keep the API up. Nothing is lost, but their memory is.
    • Sandboxes on workers continue to run during the restart. Calls to them through the API wait for the new leader.
  3. Each worker. On the primary:

    spawnbox nodes drain NODE_ID --wait

    This moves its plain sandboxes with their memory, stops its persistent sandboxes and starts them on other hosts, and copies its volumes. Read Drain a worker for what occurs to each kind. Then, on the worker, type the install command again, and wait until spawnbox nodes ls shows the worker ready with the new VERSION. Then, on the primary:

    spawnbox nodes undrain NODE_ID

    Do the next worker when this one takes sandboxes again, so that the fleet keeps the room.

Instead of a drain, you can restart a worker in place, as for the leader: its persistent sandboxes pause and resume after the restart, but its running plain sandboxes are deleted. Use this when no other host has room, or for a worker of a release before the primary, which cannot stop persistent sandboxes for a drain (node.drained then counts them as failed, and the log of the primary says that the worker is too old).

A sandbox started from a template build of an older release keeps that build. If its guest is too old for the new release, it starts again from a new build of its template; refer to Upgrades and old builds.

With the autoscaler, new workers install the latest release when they start. Upgrade the primaries as above, then retire the old workers one at a time: the primary moves their sandboxes, and the hook starts new workers as the load needs.

Retire a worker safely

To stop a worker machine without losing sandboxes, retire it first. A retired worker takes no new sandboxes and never takes them again. Use this before you stop the machine for a spot interruption, an Auto Scaling group scale-in or any other reason.

  1. On the primary, type:

    curl -s -H "$A" -X POST http://127.0.0.1:8080/v1/nodes/NODE_ID:retire \
      -d '{"reason":"spot interruption"}'

    The primary moves the sandboxes of the worker to other hosts. With {"migrate":false}, it waits for them to end instead.

  2. Get the worker until retirement.state is ready_to_terminate:

    curl -s -H "$A" http://127.0.0.1:8080/v1/nodes/NODE_ID

    retirement.waiting_for tells what the primary still waits for: sandboxes, volumes, calls (requests to the worker that are not done), settle (3 minutes after the retirement started) or heartbeat (a report from the worker after that time). If a sandbox cannot move, the state is blocked, and the primary tries again every minute.

  3. Stop the machine. Then remove the worker:

    curl -s -H "$A" -X DELETE http://127.0.0.1:8080/v1/nodes/NODE_ID

You cannot undo a retirement. :undrain gives 409 while a worker retires. Do not use systemctl stop or SIGTERM to drain a worker: the worker stops, and its sandboxes are lost.

Add and remove workers automatically

The primary can ask for workers when it is busy, and give them back when it is idle. It does not know your cloud. It calls your hook: a program or a webhook. The hook starts or stops a machine with the AWS CLI, Terraform, Pulumi or any other tool.

How it decides:

  • The load is the largest of the used slots, the used memory and the reserved memory, for the primary and the ready workers that are not drained. A host that is short of memory counts as full.
  • If a create gets 503 no_capacity, the primary asks for one more worker at once. It does not wait for --autoscale-up-after-s.
  • If the load stays above --autoscale-up-pct for --autoscale-up-after-s, the primary asks for one more worker (scale_up).
  • If there are fewer workers than --autoscale-min-workers, the primary asks for all the missing workers at once. To get ready for a known burst, raise the minimum before it starts.
  • If the load stays below --autoscale-down-pct for --autoscale-down-after-s, the primary retires the worker with the fewest sandboxes. When it is ready_to_terminate, the primary calls the hook to stop the machine (scale_down), then removes the worker.
  • Otherwise it asks for one worker at a time, and it never goes above --autoscale-max-workers. Retiring workers do not count. If the load goes up while a worker retires, the primary asks for a new worker.
  • A new worker must join within 30 minutes. If none does, the primary calls the hook to stop the machine it asked for.
  • If the hook fails, the primary sends the same request again after 5 minutes. A new primary that takes over also sends the open scale_up requests again, because it cannot know if the hook ran. The request ID and the join token stay the same. Your hook must start at most one machine for each request ID. On AWS, use the ID as the client token of run-instances.

Use the AWS example

deploy/aws/terraform has the parts for AWS:

  • A launch template for workers: Ubuntu 24.04 with nested virtualization (C8i, M8i or R8i), and the metadata service only for the host itself (IMDSv2, hop limit 1).
  • A security group: the primary calls workers on port 7444, and workers call the primary on port 7443.
  • An instance profile for the primary. It can start workers only from the template, and stop only instances with the tag spawnbox-fleet.
  • aws-hook.sh: the hook. A new worker installs Spawnbox with the install command and joins with its token.
  1. Make the parts. Use private subnets in the VPC of the primary:

    cd deploy/aws/terraform
    terraform init
    terraform apply -var region=ap-south-1 \
      -var 'subnet_ids=["subnet-..."]' \
      -var primary_security_group_id=sg-... \
      -var primary_url=https://10.0.0.1:7443
  2. Attach the instance profile primary_instance_profile to the primary. Install the AWS CLI on the primary.

  3. On the primary, install the hook and its settings:

    sudo install -m 755 aws-hook.sh /etc/spawnbox/aws-hook.sh
    terraform output -raw hook_env | sudo tee /etc/spawnbox/aws-hook.env
  4. Add these flags to SPAWNBOX_ARGS on the primary and restart: --autoscale-hook /etc/spawnbox/aws-hook.sh --autoscale-max-workers 10.

To change new workers, add these to /etc/spawnbox/aws-hook.env:

  • SPAWNBOX_WORKER_ARGS: more flags for each worker, for example "--max-sandboxes 64". The Terraform variable worker_args sets it.
  • SPAWNBOX_WORKER_SETUP: path to a script on the primary. Each new worker runs it as root at boot, before Spawnbox is installed, for example to start a monitoring agent. It goes in the EC2 user data, which is at most 16 KB. Do not change it while a worker is still to join: a request sent again must have the same user data.

With Pulumi or another tool, make the same parts and use the same hook. On Azure or GCP, change the aws commands in the hook.

Write your own hook

The primary runs the program with one argument, scale_up or scale_down. Exit code 0 means success. The program can run for at most 10 minutes. Its output goes to the log of the primary. It also gets the request as JSON on stdin, and these environment variables:

Variable Action Value
SPAWNBOX_ACTION Both scale_up or scale_down
SPAWNBOX_REQUEST_ID Both ID of the request, for example scl_.... The same request can come again.
SPAWNBOX_JOIN_TOKEN scale_up Join token for the new worker
SPAWNBOX_PRIMARY_CA_SHA256 scale_up Value for --primary-ca-sha256
SPAWNBOX_NODE_ID scale_down ID of the worker to stop, or empty
SPAWNBOX_NODE_URL scale_down --advertise URL of the worker, or empty
SPAWNBOX_NODE_SCALE_UP scale_down ID of the scale_up request that made the worker, or empty

A scale_down for a machine that is already gone must also exit 0.

If no worker joins within 30 minutes of a scale_up, the primary sends a scale_down with only SPAWNBOX_NODE_SCALE_UP set (the node’s id and url are null in the JSON), so the hook stops any machine it started for that request.

To use a webhook, give a URL to --autoscale-hook, for example --autoscale-hook https://hooks.example.com/spawnbox. The URL must use https, or http to localhost. The primary sends a POST with this JSON and waits for a 2xx response for at most 60 seconds:

{"action":"scale_up","id":"scl_...","reason":"load 82% for 120 s",
 "join":{"token":"sbj_...","ca_sha256":"...","expires_at":"2026-01-01T00:30:00.000Z"}}
{"action":"scale_down","id":"scl_...","reason":"load 12% for 1200 s",
 "node":{"id":"nod_...","url":"https://10.0.0.7:7444","scale_up":"scl_..."}}

With --autoscale-secret (or SPAWNBOX_AUTOSCALE_SECRET), each request has the header X-Spawnbox-Signature: sha256=<hex>. The value is the HMAC-SHA256 of the body with the secret.

Use your own autoscaler

Without --autoscale-hook, the primary does not start or stop machines, but it still shows what an autoscaler needs. Your tool can read these and start machines, then retire workers with :retire before it stops them:

  • GET /v1/nodes/autoscale: the load, the number of workers in each state (ready, suspect, down, draining, retiring) and recent requests. With a hook, also the settings.
  • The metrics spawnbox_fleet_load, spawnbox_fleet_create_refused_total and spawnbox_fleet_retirements. Refer to See metrics in Prometheus.

To see the state, type:

curl -s -H "$A" http://127.0.0.1:8080/v1/nodes/autoscale

The events autoscale.requested, autoscale.done, autoscale.failed, node.retiring and node.retired show each request and retirement.

This page is the “Use more than one host” section of README.md ↗. Found a mistake? Edit it on GitHub ↗