Blaxel

Perpetual sandboxes that drop into standby when idle and resume with memory intact. Native streaming exec, snapshots, fork, egress control, private previews and image builds, via @blaxel/core.

Installation

@blaxel/core (0.3 or newer) is an optional peer dependency of sbox-sdk, loaded lazily on first use.

pnpm add sbox-sdk @blaxel/core

Usage

import { createSandboxClient } from "sbox-sdk";
import { blaxel } from "sbox-sdk/blaxel";

const client = createSandboxClient({
  provider: blaxel({
    apiKey: process.env.BL_API_KEY!,
    workspace: process.env.BL_WORKSPACE!,
    region: "us-pdx-1",
  }),
});

const sandbox = await client.create({
  env: { NODE_ENV: "development" },
  lifecycle: { maxAgeMs: 2 * 60 * 60_000 }, // deleted 2h after creation
  metadata: { team: "agents" },
});

// stdout and stderr stream separately; cwd/env/timeout are native.
for await (const ev of sandbox.commands.run("npm test", { cwd: "/app" })) {
  if (ev.type === "stdout") process.stdout.write(ev.data);
}

template is the sandbox image (default blaxel/base-image:latest). A sandbox without a name gets one derived from the create call's idempotency key, so a retried create() returns the same sandbox instead of a duplicate.

Lifecycle

Blaxel puts an idle sandbox into standby by itself and resumes it (memory, processes and files intact) on the next request, so there is no explicit pause().

sboxBlaxel
lifecycle.maxAgeMs / setTimeout()ttl (maximum age, minimum 5 minutes)
lifecycle.idleTimeoutMs + onIdle: "destroy"ttl-idle expiration policy (minimum 60 seconds)
onIdle: "pause"the platform default (automatic standby)
stop()archive(): filesystem kept, memory dropped
client.connect(id)unarchives an archived sandbox
destroy()delete()

Snapshots and fork

Blaxel snapshots capture memory and running processes (includesMemory: true). snapshots.restore() rolls the sandbox back in place (same name and URLs), and client.create({ fromSnapshot }) forks a snapshot into a new sandbox. sandbox.fork() copies the live state without leaving a snapshot behind.

const snap = await sandbox.snapshots!.create({ name: "after-install" });
const [copy] = await sandbox.fork();
await sandbox.snapshots!.restore(snap);

Egress control

network at create time and sandbox.network.setEgressPolicy() at runtime map to Blaxel's egress proxy: allow-list → proxy.allowedDomains, deny → proxy.forbiddenDomains, block-all → forbiddenDomains: ["*"]. Credential injection (inject) becomes proxy routing rules with {{SECRET:name}} references, so the secret never enters the sandbox.

const sandbox = await client.create({
  network: {
    mode: "allow-list",
    domains: ["api.github.com", "registry.npmjs.org"],
    inject: [
      {
        domains: ["api.github.com"],
        headers: { Authorization: { name: "gh", value: `Bearer ${token}` } },
      },
    ],
  },
});

When a create-time policy restricts traffic, the adapter also turns on the proxy firewall ruleset so tools that ignore HTTP(S)_PROXY are filtered too. Rulesets can only be set at creation; pass egressFirewall: false to skip it. Rules are domain-based: CIDR rules throw a Validation error.

Previews and browser auth

sandbox.ports.expose(port) creates a Blaxel preview. A private preview ({ visibility: "private" }) comes back with a fresh preview token as query auth (bl_preview_token), so browserUrl() gives a URL a browser can open, including over a WebSocket (previewBrowserAuth: true). Tokens live for 24 hours by default (previewTokenTtlMs).

import { browserUrl } from "sbox-sdk";

const preview = await sandbox.ports!.expose(3000, { visibility: "private" });
const wsUrl = browserUrl(preview, { protocol: "ws", path: "/socket" });

sandbox.ports.fetch(port, path) goes through Blaxel's authenticated port proxy (proxiedFetch), so it needs no preview at all.

Templates

client.templates.build() builds an image in your workspace with Blaxel's ImageInstance builder. A build deploys a sandbox named after the template; the result's id is the image reference to pass as template. The build is tagged with its cache key, so the same spec is never rebuilt.

const tpl = await client.templates!.build({
  source: {
    dockerfile: `FROM node:22-slim
RUN apt-get update && apt-get install -y git
WORKDIR /app
COPY package.json /app/package.json`,
    context: "./my-app",
  },
});
const sandbox = await client.create({ template: tpl });

There is no Dockerfile endpoint in the SDK, so the adapter translates the Dockerfile into builder calls: FROM, RUN, ENV, WORKDIR, USER, EXPOSE, ARG, LABEL and COPY/ADD from the context are supported. Multi-stage builds, COPY --from and ADD <url> are rejected. CMD and ENTRYPOINT are skipped (with a log line), because Blaxel's sandbox API must stay the entrypoint. { image } sources (with optional registryAuth) build from a registry image directly. Building with a context needs Node (files are staged on disk).

Authentication

An API key + workspace.

Authentication variables for the blaxel adapter.
OptionEnv varRequiredDescription
apiKeyBL_API_KEYrequiredBlaxel API key.
workspaceBL_WORKSPACErequiredBlaxel workspace.
image—optionalDefault sandbox image when a spec omits `template`.

Falls back to Blaxel's standard environment (BL_API_KEY / BL_WORKSPACE) when the options are omitted.

Credentials passed as options go to the SDK's initialize(); nothing is written to process.env. Without options the SDK reads BL_API_KEY / BL_WORKSPACE or the Blaxel CLI login. initialize() is process-wide, so two blaxel() providers with different credentials in one process share the last one configured.

Options

Prop

Type

Capabilities

CapabilityLevelNotes
listnativepaginated, filtered by labels
stopnativearchive; connect() unarchives
setTimeoutnativeupdateTtl (min 5m)
pauseunsupportedstandby/resume is automatic
streaming / background / killProcessnativeprocess.exec callbacks, streamLogs, process.kill
stdinnativespawned processes (writeStdin)
filesUpload / filesWatchnativefs.writeBinary, fs.watch
exposePort / privatePreview / proxiedFetchnativepreviews + tokens, sandbox.fetch
egressControlnativeegress proxy, updateNetwork
snapshot / forknativememory included
volumes / regionnative
templateBuildnativedockerfile, image
codeInterpreter / pty / ssh / metricsunsupporteduse raw()
secretsVault / gpuunsupportedinline secrets become secret env vars

perCommandEnvCwd is true; preservesDiskOnStop and preservesMemoryOnPause (standby) are true; previewModel is subdomain.

Known limitations

  • writeStdin works on commands.spawn() processes; commands.run() doesn't open a stdin pipe, and there is no way to send EOF.
  • secrets need an inline value (they become secret env vars); Blaxel has no named secret store for sandboxes.
  • onIdle: "stop" has no Blaxel equivalent (expiration policies can only delete), so it falls back to standby.
  • A template build leaves its build sandbox deployed in your workspace (it idles in standby).

On this page