Northflank
A sandbox per Northflank deployment service, driven through @northflank/js-client. Streaming exec, PTYs, container snapshots, GPUs and metrics.
Installation
@northflank/js-client is an optional peer dependency of sbox-sdk, loaded lazily on first use. Node-only (the SDK uses Node streams and HTTP/2).
pnpm add sbox-sdk @northflank/js-clientAuthentication
An API token + the project the sandbox services live in.
| Option | Env var | Required | Description |
|---|---|---|---|
token | NORTHFLANK_TOKEN | required | Northflank API token. |
projectId | — | required | Project the sandbox services are created in. |
deploymentPlan | — | optional | Compute plan for new sandboxes (default "nf-compute-200"). |
image | — | optional | Default base image (default "ubuntu:22.04"). |
ephemeralStorageMB | — | optional | Ephemeral storage in MB for new sandboxes (default 2048). |
Create an API token in the Northflank team settings and an existing project. The live tests read NORTHFLANK_API_TOKEN, NORTHFLANK_PROJECT_ID and optionally NORTHFLANK_TEAM_ID, NORTHFLANK_PLAN.
Quickstart
import { createSandboxClient } from "sbox-sdk";
import { northflank } from "sbox-sdk/northflank";
const client = createSandboxClient({
provider: northflank({
token: process.env.NORTHFLANK_API_TOKEN!,
projectId: process.env.NORTHFLANK_PROJECT_ID!,
}),
});
const sandbox = await client.create({
template: "ubuntu:24.04",
resources: { vcpus: 2, memoryMB: 4096 },
lifecycle: { maxAgeMs: 2 * 60 * 60_000 }, // service expires after 2 h
});
for await (const ev of sandbox.commands.run("apt-get update")) {
if (ev.type === "stdout") process.stdout.write(ev.data);
}
await sandbox.destroy();A sandbox is a deployment service running the image (deployment.external.imagePath) with a sleep infinity command. create() waits until the deployment is COMPLETED (or fails) before returning.
How it maps
| Spec field | Northflank |
|---|---|
template | deployment.external.imagePath (registryCredentials for private images) |
env, inline secrets | runtimeEnvironment |
metadata | the service description (sbox:{json}), so list() can filter it |
resources.vcpus/memoryMB | smallest fitting billing.deploymentPlan (override with deploymentPlan) |
resources.diskMB/shmMB | storage.ephemeralStorage.storageSize, storage.shmSize |
resources.gpu/gpuCount | billing.gpu.configuration |
lifecycle.maxAgeMs | createOptions.expiryTime (5 min – 7 days; the service is paused, then deleted) |
ports | public HTTP ports |
volumes | createOptions.volumesToAttach (the volume's mount is set to mountPath) |
fromSnapshot | deployment.containerSnapshot.restoreFrom |
name / idempotencyKey | the service name; without a name it is derived from the idempotency key, so a retried create reuses the service |
Exec, PTY and files
commands.run()streams overexec.execServiceSessionwith separate stdout/stderr and the real exit code;writeStdinfeeds the session's stdin.- Each command records its shell pid in
/tmp/.sbox-<id>.pid;kill()andtimeoutMsSIGKILL that process tree. sandbox.pty.create()is a tty exec session (sendInputToCurrentCommand,resizeTerminal).pty.connect(id)works within the same process.- Files use the SDK's streaming copy (
upload/download.serviceStream.files), which needstarandcatin the image. - No per-command
cwd/env: the core wraps the command (perCommandEnvCwd: false).
Previews
ports.expose(port) adds a public HTTP port without touching the others (the update endpoint replaces the whole list, so the adapter merges) and returns https://<port-name>--<service>.code.run. visibility: "private" protects the port with HTTP basic auth:
const p = await sandbox.ports.expose(3000, { visibility: "private" });
// p.auth = { type: "header", headers: { authorization: "Basic …" } }Basic auth is a header, so a private preview can't be opened from a browser WebSocket (previewBrowserAuth: false).
Snapshots and fork
snapshots.create() takes a Northflank container snapshot (filesystem only, includesMemory: false) and waits for it to succeed. snapshots.restore() redeploys the service from it, client.create({ fromSnapshot }) boots a new service from it, and sandbox.fork() snapshots and restores into new services.
Container snapshots need a cluster with the Kata runtime (sandboxed
workloads). gVisor/Kata are a cluster setting on Northflank
(sandboxing.defaultSandbox.services for BYOC clusters), not a per-service
option, so the adapter has no runtime-class option.
Templates
Northflank builds images from a git repository or a bundle URL, so a raw Dockerfile + local context can't be uploaded. templates.build() accepts { image } only: the template id is the image path plus any env/startCmd/workdir, encoded into the id so it works across processes.
const tpl = await client.templates.build({
source: { image: "node:22" },
env: { NODE_ENV: "production" },
});
const sb = await client.create({ template: tpl });Options
Prop
Type
Capabilities
| Capability | Level | Notes |
|---|---|---|
list | native | cursor pagination, metadata filter |
pause | native | scale to zero; memory and disk are lost |
streaming / stdin / pty | native | exec sessions |
exposePort / privatePreview | native | public port; basic auth when private |
snapshot / fork | native | container snapshots (Kata clusters) |
gpu / metrics | native | billing.gpu; metrics.getServiceMetrics |
templateBuild | native | image sources only |
stop / setTimeout | unsupported | maxAgeMs is set once at create |
ssh | unsupported | the API does not expose an SSH endpoint |
volumes / secretsVault | unsupported | attach existing volumes via spec.volumes |
region | unsupported | fixed by the project's cluster |
Flags: perCommandEnvCwd: false, preservesMemoryOnPause: false, previewModel: "subdomain", templateSources: ["image"].
Limitations
pause()scales to zero: the container and its ephemeral disk go away. Mount a volume for data that must survive.deployment.ssh.enabledexists, but the API gives no host/port to connect to, sosshstays unsupported.- Plan selection from
resourcesuses a built-in table of Northflank plan ids; passdeploymentPlanto pin one.
Railway
Isolated Debian Linux VMs on Railway, with streaming exec, real kill, background sessions you can reattach to, native files, checkpoints, forks and preview domains.
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.