Fly Machines
A sandbox per Fly Machine over the Machines REST API. Pure fetch, no SDK, so it runs anywhere the core does, including the edge.
Installation
No provider SDK required: the adapter talks to the Fly Machines REST API with fetch (the client's fetch, so tests and proxies can inject their own).
pnpm add sbox-sdkAuthentication
An API token + the target app name.
| Option | Env var | Required | Description |
|---|---|---|---|
apiToken | FLY_API_TOKEN | required | Fly API token (`fly auth token`). |
appName | FLY_APP_NAME | required | The Fly app the machines run in (must already exist). |
region | FLY_REGION | optional | Default region, e.g. "iad". |
image | — | optional | Default machine image. |
appDomain | — | optional | Public app domain for preview URLs; defaults to <appName>.fly.dev. |
apiBaseUrl | — | optional | Override the Machines API base URL. |
You need an API token (fly tokens create deploy -a <app> or an org token) and an existing app: each sandbox is a Machine inside it. The live tests read FLY_API_TOKEN, FLY_APP_NAME and optionally FLY_REGION.
Quickstart
import { createSandboxClient } from "sbox-sdk";
import { fly } from "sbox-sdk/fly";
const client = createSandboxClient({
provider: fly({
apiToken: process.env.FLY_API_TOKEN!,
appName: process.env.FLY_APP_NAME!, // must already exist
region: "iad",
}),
});
const sandbox = await client.create({
template: "node:22", // any image; default ubuntu:22.04
resources: { vcpus: 2, memoryMB: 1024, diskMB: 8192 },
metadata: { team: "agents" },
});
const res = await sandbox.commands.run("node -v");
console.log(res.stdout);
await sandbox.destroy();template is the Machine's container image. Machines boot with init.exec = ["sleep","inf"] and restart: { policy: "no" }, so plain images (whose CMD would exit) stay up and a stopped machine stays stopped. Pass keepAlive: false for images that run their own long-lived process.
How it maps
| Spec field | Fly Machines API |
|---|---|
template | config.image |
env | config.env |
metadata | config.metadata (filterable server-side with metadata.<key>= on list) |
resources | guest.cpus, guest.memory_mb (rounded up to 256 MB, 1024 for performance), rootfs.size_gb |
region | region |
ports | machine services (see previews) |
lifecycle.onIdle | services[].autostop (pause → suspend, stop → stop), autoResume → autostart |
volumes | config.mounts (Fly allows one volume per machine) |
secrets (with value) | app secret (POST /apps/{app}/secrets/{name}) + min_secrets_version |
idempotencyKey | sbox-idem metadata; a retried create returns the existing machine |
The root filesystem uses rootfs.persist = "always" (opt out with persistRootfs: false), so files survive stop()/resume() and the restarts caused by config updates.
Exec and files
/execis buffered and limited to 600 s per command.timeoutMsis passed through (clamped); commands without one getexecTimeoutSec(default 600). Longer jobs should be started detached (nohup … &) and polled.kill()finds the command through/ps(every exec carries a unique$0marker) and SIGKILLs its process tree from inside the machine.commands.list()is/ps;commands.kill(pid)signals any pid.- File writes send the bytes in the exec request's
stdinfield (never argv), in 768 KiB chunks, so large and binary files round-trip. Reads fall back to chunkedddwhen a response would exceed Fly's output limit. - There is no per-command
cwd/env, so the core wraps the command (perCommandEnvCwd: false).
Previews
Fly routes per app, not per machine: the URL is always https://<app>.fly.dev (or appDomain). ports.expose(port) adds a machine service (the first port on 443, later ones on their own number) and returns:
const p = await sandbox.ports.expose(8080);
// { url: "https://my-app.fly.dev", auth: { type: "header", headers: { "fly-force-instance-id": "<machine id>" } } }
await sandbox.ports.fetch(8080, "/health"); // adds the header for youThe fly-force-instance-id header pins the request to this machine; without it Fly Proxy may route to any machine of the app that serves the same port. Because it is a header, it can't be set from a browser WebSocket (previewBrowserAuth: false). It is a routing header, not authentication: the service is public. The app needs a public IP (fly ips allocate-v6, or a shared v4).
Exposing a port on a running machine updates its config, which restarts
the machine (files survive thanks to rootfs.persist, processes do not).
Declare ports up front with spec.ports to avoid the restart.
Volumes and secrets
const vol = await client.volumes.create({
name: "data",
sizeMB: 10_240,
region: "iad",
});
const sb = await client.create({
region: "iad",
volumes: [{ id: vol.id, mountPath: "/data" }],
});secrets: [{ name: "API_KEY", value }] writes an app secret, which every machine in the app can read. A secret without value must already exist and is exposed under its own name.
Options
Prop
Type
Capabilities
| Capability | Level | Notes |
|---|---|---|
list / region | native | fly-next-cursor pagination |
stop / pause | native | pause = suspend (memory kept) |
killProcess | native | /ps + kill inside the machine |
exposePort / proxiedFetch | native | app URL + fly-force-instance-id |
volumes / secretsVault | native | Fly volumes; app secrets |
streaming | emulated | /exec is buffered |
privatePreview | unsupported | Fly previews are public; the header only routes |
gpu | unsupported | the Machines API rejects GPU requests |
snapshot / fork | unsupported | volume snapshots are not machine snapshots |
setTimeout / background | unsupported | |
pty / ssh / stdin | unsupported | /exec has no interactive stream |
Flags: perCommandEnvCwd: false, preservesMemoryOnPause: true, preservesDiskOnStop: true (with persistRootfs), previewModel: "declaredPorts".
Limitations
- 600 s per exec call; output is returned only when the command ends.
lifecycle.idleTimeoutMsandmaxAgeMshave no Fly equivalent (Fly Proxy decides when an idle service autostops).verify()callsGET /apps/{app}and returns the org slug.
Northflank
A sandbox per Northflank deployment service, driven through @northflank/js-client. Streaming exec, PTYs, container snapshots, GPUs and metrics.
AWS Lambda MicroVMs
Firecracker-based serverless sandboxes with suspend/resume and idle policies. Control plane via @aws-sdk/client-lambda-microvms; a small runner baked into the image handles exec and files.