Runtime pools (beta)
Start worker runtimes on demand with pools, controllers, and push delivery
Runtime pools let the API start workers when tasks need capacity and stop workers when their lifecycle ends.
The feature is BETA and defaults to off. Set RUNTIME_POOLS_ENABLED=true and keep MULTI_RUNTIME_ENABLED=true on the API.
Restart the API after enabling pools so it can seed built-in controllers.
The dashboard requires API version 1.169.0 or later. Development deployments can use SWARM_DEV_MODE=true to bypass that version check.
With pools disabled, existing workers keep their registration and poll behavior. Pool and controller routes return 404.
Concepts
| Concept | Purpose |
|---|---|
| Agent | Durable identity, profile, credentials, task queue, and logical maxTasks limit. |
| Pool | Infrastructure kind, controller placement, worker image, delivery mode, lifecycle, and capacity limits. |
| Controller | Starts and stops runtimes through Docker, E2B, or boxd. A built-in controller runs inside the API. A remote controller runs elsewhere. |
| Runtime | One worker process serving an agent. It has its own identity, slots, liveness record, and scoped credential. |
An agent binds to one pool. A pool has one controller placement in this release. Several runtimes can serve the same agent. Pool workers use the multi-runtime rules. Workspace files remain local to each runtime unless the pool sets a persistent workspace. Otherwise, save durable results in Git, shared storage, or attachments before a runtime exits.
Recommended topology
Keep one Lead on a static pool with delivery: "poll". Operators manage static workers themselves.
Put coding agents on a docker, e2b, or boxd pool with delivery: "push" and on-demand capacity.
Use minRuntimes: 0 to permit an agent to sleep when no work remains.
The router first selects an eligible live worker with free capacity.
After RUNTIME_WAKE_GRACE_SEC (default 15 seconds), it can assign work to an eligible sleeping pool agent.
The supervisor then provisions capacity after budget admission.
Tasks retain their role, capability, and model compatibility requirements.
An open circuit prevents assignments to sleeping agents. Existing runtimes can continue their tasks.
Docker pools
The API needs access to a Docker Unix socket. TCP Docker endpoints are unsupported.
DOCKER_HOST defaults to unix:///var/run/docker.sock. On OrbStack, use unix://$HOME/.orbstack/run/docker.sock.
RUNTIME_DOCKER_HOST seeds an explicit socket into the built-in controller, even when Docker is offline.
Existing controller configuration takes precedence over later changes to that seed setting.
DOCKER_NETWORK selects the worker network. DOCKER_EXTRA_HOSTS adds comma-separated host:address entries.
Workers must reach the API through controller WORKER_API_URL, deployment RUNTIME_WORKER_API_URL, or the public API URL.
For a host API and local Docker workers, use http://host.docker.internal:<api-port>.
For a shared Docker network, use an API hostname on that network.
Set API to your API origin and export AGENT_SWARM_API_KEY before these commands.
First discover controller IDs:
curl -s -H "Authorization: Bearer $AGENT_SWARM_API_KEY" \
"$API/api/runtime-controllers" | jq '.controllers[] | {id, kind, status}'Create a pool and its offline agent:
POOL=$(curl -s -X POST "$API/api/runtime-pools" \
-H "Authorization: Bearer $AGENT_SWARM_API_KEY" -H 'Content-Type: application/json' \
-d '{"name":"coders","kind":"docker","placements":["builtin-docker"],"image":"ghcr.io/desplega-ai/agent-swarm-worker:slim","delivery":"push","lifecycle":"per-task","slotsPerRuntime":1,"maxRuntimes":3}' \
| jq -r '.pool.id')
CODER=$(curl -s -X POST "$API/api/runtime-pools/$POOL/agents" \
-H "Authorization: Bearer $AGENT_SWARM_API_KEY" -H 'Content-Type: application/json' \
-d '{"name":"coder-1","maxTasks":3}' | jq -r '.agent.id')
curl -s -X POST "$API/api/tasks" \
-H "Authorization: Bearer $AGENT_SWARM_API_KEY" -H 'Content-Type: application/json' \
-d "{\"task\":\"Report pong through store-progress\",\"agentId\":\"$CODER\",\"routingReason\":\"human_pinned\",\"modelTier\":\"smol\"}"Configure the agent's harness and credentials before sending real tasks.
An unassigned task can also select this agent after wake grace, provided no other eligible worker has live capacity.
The dashboard exposes pools and controllers under Settings. The agent page can bind an existing agent to a pool.
The API returns 200 for pool and controller writes. Task creation returns 201.
Pool and controller writes require operator credentials or a user account. A pool selects the image that receives a runtime token, so agents cannot create, change, or delete pools. A Lead can list pools, create an agent in an existing pool, and bind an agent to a pool.
Persistent caches
Docker pools can share one persistent cache across their runtimes. Caching is off by default. Configure it through the pool API:
curl -s -X PATCH "$API/api/runtime-pools/$POOL" \
-H "Authorization: Bearer $AGENT_SWARM_API_KEY" -H 'Content-Type: application/json' \
-d '{"cache":{"mountPath":"/home/worker/.cache"},"env":{"BUN_INSTALL_CACHE_DIR":"/home/worker/.cache/bun","npm_config_cache":"/home/worker/.cache/npm"}}'The env object replaces the pool's environment settings, so include any values
you already use. Make the mount writable for your image's worker user through
your image or root setup script. Cache configuration mounts storage; the package
manager environment variables select where tools put their caches.
The swarm chooses the volume name, swarm-cache-<poolId>-<generation>. Every runtime in that
pool on the same controller target shares the current generation, while its working disk remains
ephemeral. Only use caches that support concurrent writers. Keep working trees,
credentials and runtime state outside the shared cache.
Mount paths cannot overlap workspace roots (/workspace/personal and
/workspace/shared) or credential and harness state directories: the directory
itself, its ancestors and its descendants are rejected. Entire worker homes are
also rejected. Use a cache directory outside these protected trees, such as
/home/worker/.cache, /root/.cache, /workspace/cache, or /cache.
Terminating a runtime preserves its cache. Set "cache": null to stop mounting it
in new runtimes and schedule automatic cleanup. Existing runtimes keep their
mounts until they stop; cleanup waits for them, without waiting for new runtimes
that do not use the cache. Deleting a pool or moving its placement also schedules
cleanup on the old controller. Setting "enabled": false retains the configured
cache for when the pool is enabled again.
Cleanup survives API restarts and retries when the controller is offline or the
volume is still in use. Docker verifies ownership and never forces removal.
Re-enabling cache starts a fresh generation while the retired generation is
cleaned up. A delayed or timed-out deletion cannot remove the new cache.
Ordinary pool edits retain its generation. Abandoned cleanup claims retry after
five minutes following an API restart. Disable caches and wait for cleanup before changing a
controller's target, placement or credentials, or deleting the controller.
Deferred cleanup errors appear in the API logs and
runtime_cache_releases.last_error; upgrade older controllers to complete cleanup.
Static, E2B and boxd pools currently reject this setting. Controllers declare
persistentCache separately from ephemeralDisk; an older Docker controller
starts without the cache and reports the reason in the pool's lastError.
A failed volume preparation also falls back without cache and reports a warning.
A mount failure during container creation or start retries once without the
cache, after removing any failed-start container. Other failures still fail the
provision.
The API never adopts a volume labeled for another swarm or pool.
Persistent workspaces
A pool can keep each agent's /workspace/personal across runtimes: Git clones,
node_modules, worktrees and setup state stay warm between tasks. It is off by default.
curl -s -X PATCH "$API/api/runtime-pools/$POOL" \
-H "Authorization: Bearer $AGENT_SWARM_API_KEY" -H 'Content-Type: application/json' \
-d '{"workspace":{}}'In the dashboard, open the pool under Settings and turn on Persistent workspace. The switch shows only for the kinds that support it, and Kubernetes pools also get a New claim size field. A save that leaves the switch alone keeps the stored setting. The pool page shows the current setting in its side panel, and for a Kubernetes pool the size a new claim gets.
| Kind | Support |
|---|---|
docker | Yes, a named volume per workspace. sizeGb is ignored: the local driver has no quota. |
k8s | Yes, a ReadWriteOncePod PersistentVolumeClaim per workspace, sizeGb (default 20) Gi. Needs Kubernetes 1.29+ and a CSI driver that supports the access mode. Set K8S_STORAGE_CLASS on the controller to pick the storage class, and grant the API get and create on persistentvolumeclaims. |
e2b | No. E2B volumes are in private beta and E2B advises against Git and package installs on them. Pause and resume already keep the sandbox disk. |
boxd | Not yet. |
static | Not applicable. The operator owns the worker's disk. |
The API rejects a workspace on an unsupported kind.
Size. sizeGb and K8S_STORAGE_CLASS apply only when a claim is created. A
runtime reuses its agent's existing claim as it is, so changing the size from 20 to
50 saves the pool and leaves every existing claim at 20 Gi. The dashboard shows the
pool setting, never the size of the claims in the cluster. Resize an existing claim
yourself. This needs a storage class with allowVolumeExpansion: true, and a claim
can only grow:
kubectl -n <namespace> get pvc -l swarm.workspace=true
kubectl -n <namespace> patch pvc swarm-ws-<agentId>-<slot> \
-p '{"spec":{"resources":{"requests":{"storage":"50Gi"}}}}'Slots. Each runtime takes the lowest workspace slot no other live runtime of
the same agent holds, and mounts the volume swarm-ws-<agentId>-<slot>. An agent
with one runtime always uses slot 0. With several concurrent runtimes (for example
lifecycle: "per-task" and maxTasks above 1), each slot has its own copy of the
workspace: files outside Git, such as todos.md or memory/, differ by slot. Two
live runtimes never share a volume. For coding agents, prefer lifecycle: "idle"
with one runtime per agent.
Fail closed. Unlike the cache, a runtime never starts without its workspace. A volume error, a volume another container still uses, or a controller that does not confirm the mount fails the provision and counts toward the pool's failure backoff. A runtime gets no work until its mount is confirmed, and a runtime that a reconnecting controller cannot show mounting its workspace is terminated. Upgrade remote controllers before enabling workspaces.
Retention. The swarm never deletes a workspace. Terminating a runtime, disabling the setting, deleting the pool, changing its placement or image, and recovery all keep the volume. A placement change gives the agent fresh, empty volumes on the new controller; the old ones stay where they were. Remove a workspace yourself once no runtime uses it:
docker volume ls --filter label=swarm.workspace=true
docker volume rm swarm-ws-<agentId>-<slot>
# Kubernetes
kubectl -n <namespace> get pvc -l swarm.workspace=true
kubectl -n <namespace> delete pvc swarm-ws-<agentId>-<slot>On boot, the worker fetches and resets clean default-branch checkouts it finds in
the workspace instead of cloning again. A clone interrupted mid-way is moved aside
to <repo>.incomplete-<timestamp> and cloned again.
Push and poll delivery
Push workers dial /api/realtime. They need no inbound port.
The socket sends nudges for work, cancellation, steering, and configuration changes.
A nudge carries no task content or secrets. Workers fetch current state through the existing API endpoints.
Workers also fetch after reconnecting and every 30 seconds by default for safety.
They retain a 30-second liveness ping. A socket unavailable for 60 seconds causes temporary poll fallback.
The register response selects the pool's delivery mode, then RUNTIME_DEFAULT_DELIVERY, then poll.
A valid worker SWARM_DELIVERY_MODE=poll|push overrides that selection.
RUNNER_PUSH_SAFETY_POLL_MS changes the safety interval in the worker environment.
The worker logs its active mode and source at startup and whenever the mode changes.
Check the Delivery mode: log when diagnosing unexpected polling or push behavior.
Socket fallback and reconnect also log the mode.
A Lead with LEAD_MONITOR_CHANNELS=true must use poll delivery because polling computes channel activity.
This restriction overrides a worker's request for push delivery.
Changes to pool delivery apply at the worker's next registration.
Lifecycles and capacity
| Setting | Behavior |
|---|---|
lifecycle: "idle", idleMinutes: null | Keep runtimes indefinitely. This represents the "never exit" policy. |
lifecycle: "idle", positive idleMinutes | Stop idle runtimes after that interval, while retaining the warm floor. |
lifecycle: "per-task" | Exit after task completion. Use slotsPerRuntime: 1 for one task per runtime. |
slotsPerRuntime | Maximum concurrent tasks for one provisioned process. |
Agent maxTasks | Logical capacity across that agent's runtimes. Keep it at least as large as slotsPerRuntime. |
Pool maxRuntimes | Physical limit across all agents in the pool. Provisioning runtimes count. null removes this pool limit. |
Pool minRuntimes | Warm floor for each bound agent, within the agent and pool limits. |
Workers receive a scoped runtime token instead of the operator key.
The token binds the agent and runtime identities. Conflicting identity headers return 403.
The token can read the agent's resolved secrets and mint task tokens for its assigned tasks.
Infrastructure credentials remain with the controller. Workers do not receive them.
Termination revokes the runtime token and its task tokens. Calls with revoked tokens return 401.
Runtime death uses heartbeat recovery to preserve work through resume tasks.
E2B pools
Choose kind: "e2b" with an E2B controller and an HTTPS API URL reachable by the sandbox.
Store E2B_API_KEY in the controller's encrypted secret configuration.
The seeded builtin-e2b controller can inherit the deployment key. Other controllers require their own key.
E2B_API_BASE selects a custom API endpoint. Controller configuration overrides the API environment fallback.
A plain image names an existing E2B worker template.
A docker:// image reference builds a template during first provision and caches the resolved template on the pool.
Custom images must extend an Agent Swarm worker image. Image and resource changes invalidate the cache.
Template construction requires E2B credentials available to the API, including when a remote controller serves the pool.
Set pool ttlSec to request a lease. The default is 900 seconds.
The supervisor renews wanted runtimes near expiry and stores the expiry that E2B applied.
If the API stops, lease expiry bounds sandbox lifetime.
E2B_MAX_CONTINUOUS_SEC defaults to 3600 seconds for Hobby. Pro deployments can configure 86400 seconds.
The setting describes the account limit. It does not increase that limit.
The supervisor drains runtimes before the continuous limit and permits replacements within the pool cap.
Busy runtimes finish their tasks while draining. Tasks longer than the limit can still need crash recovery.
Automatic idle pause is not available in this release.
Use an idle lifecycle or warm floor to reduce repeated sandbox boot cost for frequent tasks.
boxd pools
Choose kind: "boxd" with a boxd controller and an HTTPS API URL reachable by the machine.
Each runtime is one isolated boxd microVM that runs the pool image in its own Docker daemon.
Use the same worker images as Docker pools.
Set BOXD_API_KEY on the API and restart it to seed an online builtin-boxd controller. Other controllers store the key in their encrypted secret configuration.
An org API key selects its org. Set BOXD_ORG in controller configuration for a personal key.
For setup, snapshots, and limits, see boxd runtime provider.
| Controller setting | Behavior |
|---|---|
BOXD_SNAPSHOT | Restore this snapshot instead of booting a fresh machine. The snapshot's size applies. |
BOXD_DELETE_AFTER_SEC | Delete each machine this many seconds after creation, in any state. A safety net for per-task pools. |
BOXD_BASE_URL | Another boxd API endpoint. |
BOXD_START_TIMEOUT_SEC | Seconds docker run may take to start the worker, image pull included. Default 600. |
BOXD_STATUS_TIMEOUT_SEC | Seconds a status check waits for docker inspect. Default 15. |
BOXD_TEARDOWN_TIMEOUT_SEC | Seconds terminate waits for boxd to confirm the machine is gone. Default 30. |
Pool resources select the smallest size that covers them: 1 vCPU and 4 GiB, 2 and 8, 4 and 16, or 8 and 32.
Machines have no lease. They run until the supervisor terminates them, so keep the API running or set BOXD_DELETE_AFTER_SEC.
A fresh machine pulls the image on each provision. With the slim worker image, provision took about 40 seconds.
A snapshot with the image already pulled provisions in about 3 seconds. Bake one and set BOXD_SNAPSHOT:
boxd machine new swarm-base --isolated
boxd machine exec swarm-base -- docker pull ghcr.io/desplega-ai/agent-swarm-worker:slim
boxd snapshots save swarm-base swarm-worker-slim
boxd machine remove swarm-base --confirmRemote controllers
Use a remote controller when the API cannot reach the infrastructure that starts workers.
Create a controller with placement: "remote" and the appropriate kind.
Set controller WORKER_API_URL to an API origin reachable by its workers.
Use the controller's ID in the pool's placements array.
Mint its token using operator credentials or an authorized user account:
curl -s -X POST "$API/api/runtime-controllers/<controller-id>/token" \
-H "Authorization: Bearer $AGENT_SWARM_API_KEY"The response returns the plaintext once. Save it as AGENT_SWARM_CONTROLLER_TOKEN on the controller host.
Minting another token revokes the previous token and disconnects its session.
Start the controller next to Docker:
export AGENT_SWARM_CONTROLLER_TOKEN=<controller-token>
agent-swarm controller --api-url https://api.example.test --kind docker \
--docker-host unix:///var/run/docker.sock --docker-network swarm-workersThe CLI reads the token from the environment. It does not accept a --token flag.
Infrastructure credentials stay on that host. The controller needs no inbound port.
On reconnect, it lists runtimes belonging to this swarm before becoming online.
Disconnect stops new provisioning. Existing runtime records survive the controller grace, which defaults to 120 seconds.
After grace expiry, the API revokes their tokens and recovers active tasks.
Run the controller as a service
Run the controller under a supervisor so it restarts after a crash or a host reboot.
The controller reconnects by itself after network loss. It detects a silent link within 60 seconds and then retries with backoff. A revoked token makes it exit, so mint a new token and restart it.
Pass each flag and its value as two separate arguments. The CLI rejects the --flag=value form.
Docker Compose. The worker image contains the agent-swarm binary, so the host needs no Bun install.
Use the same image tag as your workers. Create the worker network first: docker network create swarm-workers.
services:
swarm-controller:
image: ghcr.io/desplega-ai/agent-swarm-worker:latest
entrypoint: ["/usr/local/bin/agent-swarm", "controller"]
command:
- --api-url
- https://api.example.test
- --kind
- docker
- --docker-host
- unix:///var/run/docker.sock
- --docker-network
- swarm-workers
user: root # needed to open the Docker socket
environment:
AGENT_SWARM_CONTROLLER_TOKEN: ${AGENT_SWARM_CONTROLLER_TOKEN:?set the controller token}
volumes:
- /var/run/docker.sock:/var/run/docker.sock
restart: unless-stoppedAGENT_SWARM_CONTROLLER_TOKEN=<controller-token> docker compose up -d
docker compose logs -f swarm-controllerFor an E2B controller, set --kind e2b, remove the Docker flags and the socket volume, and add E2B_API_KEY to environment.
For a boxd controller, set --kind boxd and add BOXD_API_KEY instead. Like E2B, the controller checks for an HTTPS worker URL in its own environment, so also set MCP_BASE_URL to the public API URL.
systemd. Run the CLI with Bun under a dedicated user in the docker group.
Membership in the docker group gives root-equivalent access to the host, so keep this user for the controller only.
sudo useradd --system --create-home --shell /usr/sbin/nologin --groups docker swarm-controller
sudo -u swarm-controller bash -c 'curl -fsSL https://bun.sh/install | bash'
sudo install -d -m 700 /etc/agent-swarm
sudo install -m 600 /dev/null /etc/agent-swarm/controller.env
echo 'AGENT_SWARM_CONTROLLER_TOKEN=<controller-token>' | sudo tee /etc/agent-swarm/controller.env >/dev/null[Unit]
Description=Agent Swarm runtime controller
Wants=network-online.target
After=network-online.target docker.service
Requires=docker.service
[Service]
User=swarm-controller
EnvironmentFile=/etc/agent-swarm/controller.env
ExecStart=/home/swarm-controller/.bun/bin/bunx @desplega.ai/agent-swarm@<version> controller \
--api-url https://api.example.test --kind docker \
--docker-host unix:///var/run/docker.sock --docker-network swarm-workers
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl enable --now agent-swarm-controller
journalctl -u agent-swarm-controller -fPin <version> to your API version. For an E2B controller, put E2B_API_KEY in the environment file and drop the Docker flags and the docker unit dependency.
Benchmarks
These numbers come from the v1 test runs on 2026-10-11. Use them as a rough guide, not as a guarantee.
Each task was a one-line "pong" task. The model was openrouter/deepseek/deepseek-v4.1-flash on the pi harness.
The worker image was built from the same code as this release.
One worker, 100 tasks
A Lead got one task: send 100 pong tasks to one pool agent. The agent had maxTasks: 5, slotsPerRuntime: 5, maxRuntimes: 1, and push delivery.
| Metric | Docker (local) | E2B (through a tunnel) |
|---|---|---|
| Tasks completed | 100 of 100 | 100 of 100 |
| Failed, lost, or duplicate tasks | 0 | 0 |
| Runtimes alive at the same time | 1 | 1 |
| Wall clock, first task to last completion | 75 s | 631 s |
| Task create to done, p50 / p95 | 10 s / 17 s | queue-bound |
| Model spend | $0.17 | $0.30 |
On E2B, the worker filled only 2 of its 5 slots. Each request from the sandbox crossed a tunnel with about 0.4 s of latency, and the runner makes many API calls for each task. Use a low-latency, public API URL for E2B pools.
E2B scale-out, one sandbox per task
One pool agent with lifecycle: per-task, slotsPerRuntime: 1, and maxRuntimes equal to the wave size. Tasks were created through the API.
| Wave | Tasks completed | Peak sandboxes | All sandboxes started | All tasks done |
|---|---|---|---|---|
| 10 | 10 of 10 | 10 | 31 s | 77 s |
| 25 | 25 of 25 | 25 | 74 s | 162 s |
| 50 | 50 of 50 | 50 | 22 s | 389 s |
The 10 and 25 waves ran before concurrent provisioning existed. The 50 wave used it (RUNTIME_PROVISION_CONCURRENCY, default 8). Without it, the 50th sandbox started 147 s after the first.
The API stayed below 41% CPU. The limit was the single free tunnel between the sandboxes and the API: sandbox registration p50 rose to about 2 minutes, and some sandboxes lost their MCP connection.
E2B spend was below $1 per wave of 50 at 2 vCPU and 2 GiB per sandbox.
Remote controller on a Docker 29 host
The API ran on a laptop. The controller and its containers ran on a remote Linux host, connected through an SSH reverse tunnel.
| Test | Result |
|---|---|
| One task | Completed in 27 s. The container exited about 14 s after the task, when the runner finished its post-task work. |
10 tasks, maxRuntimes: 5 | All completed in 96 s. Never more than 5 containers. |
| Controller killed within the grace | No new containers during the outage. Reconcile after restart. |
| Controller killed past the grace | Runtime tokens revoked, task superseded and resumed after restart. |
| Network drop at task finish | The runner retried, then saved the result. No re-run. |
Troubleshooting
| Symptom | Check |
|---|---|
| Settings pages are absent | Confirm the BETA flag, API version gate, and runtime_pools status in GET /status. |
| Supervisor does not run | Keep MULTI_RUNTIME_ENABLED=true and inspect GET /status. |
| Task remains unassigned | Check wake grace, affinity, model compatibility, budgets, agent capacity, pool enabled state, and circuit status. |
| Runtime never registers | Check WORKER_API_URL reachability and worker image contents. Registration timeout defaults to 300 seconds. |
| Circuit remains open | Read pool lastError, consecutiveFailures, and circuitOpenUntil. Correct the provider or image failure before the trial provision. |
| Remote controller stays offline | Check its token, provider kind, API URL, and host logs. Controller tokens cannot authenticate worker routes. |
| Push worker polls frequently | Check Delivery mode: logs, SWARM_DELIVERY_MODE, socket fallback, and the safety interval. |
| E2B task stops near the limit | Confirm the account tier, lease renewal, draining state, and continuous runtime limit. |
Inspect runtimes with GET /api/runtime-pools/<pool-id>/runtimes.
Provider errors are scrubbed before storage. Unknown provider status alone does not prove runtime death.
Provision retries wait 30, 90, then 180 seconds. After the attempt limit, the oldest ready pending task fails and notifies the Lead.
The pool circuit blocks new provisioning after repeated failures and permits one trial after its expiry.
First registration closes the circuit. Healthy re-registration does not reset it.
See Configuration for environment settings and defaults. Maintainers can consult the runtime provider runbook.