Beam Cloud

A sandbox per Beam Cloud container. GPU-capable sandboxes with native streaming exec, processes, filesystem, egress control, brokered secrets, memory snapshots and image builds, via @beamcloud/beam-js.

Installation

@beamcloud/beam-js (1.1 or newer) is an optional peer dependency of sbox-sdk, loaded lazily on first use.

pnpm add sbox-sdk @beamcloud/beam-js

Authentication

An API token + workspace id.

Authentication variables for the beam adapter.
OptionEnv varRequiredDescription
tokenBEAM_TOKENrequiredBeam API token.
workspaceIdBEAM_WORKSPACE_IDrequiredBeam workspace id.
image—optionalDefault base image when a spec omits `template`.

Token and workspace fall back to the standard Beam environment when the options are omitted.

The adapter reads BEAM_TOKEN and BEAM_WORKSPACE_ID, or takes token / workspaceId options.

@beamcloud/beam-js keeps its credentials in a process-wide beamOpts object and builds its HTTP client once. Only one Beam token per process works. A provider configured with a different token fails with a Validation error instead of quietly using the first token.

Usage

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

const client = createSandboxClient({
  provider: beam({
    token: process.env.BEAM_TOKEN!,
    workspaceId: process.env.BEAM_WORKSPACE_ID!,
  }),
});

const sandbox = await client.create({
  template: "python:3.12-slim", // registry image (Image.fromRegistry)
  resources: { vcpus: 2, memoryMB: 2048, gpu: "A10G" },
  lifecycle: { maxAgeMs: 30 * 60_000 }, // Beam TTL (keepWarmSeconds)
  env: { APP_ENV: "dev" },
  volumes: [{ id: "weights", mountPath: "/mnt/weights" }],
  secrets: [{ name: "OPENAI_API_KEY", mode: "egress" }],
  network: { mode: "allow-list", domains: ["api.openai.com", "*.pypi.org"] },
});

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

What create() maps to

sboxBeam
template (registry ref)Image.fromRegistry(ref)
template (Beam image id / template ref)Image.fromId(id)
namethe Beam app name (default "sbox", or the app option)
resources.vcpus / memoryMBcpu / memory
resources.gpu / gpuCountgpu / gpuCount (T4, L4, A10G, A100-40, A100-80, H100, A6000, RTX4090, L40S, any)
lifecycle.maxAgeMs, setTimeout()keepWarmSeconds / updateTtl (a TTL, default 600s)
envenv
volumesnew Volume(id, mountPath) (created on first mount)
secrets by namesecrets: [{ name }] (brokered workspace secrets)
secrets with an inline valueplain env var
networkblockNetwork / allowList
portsports (public URLs at creation)
fromSnapshotSandbox.createFromSnapshot (memory) or Image.fromId (filesystem)

Settings Beam cannot honor throw Validation instead of being dropped:

  • lifecycle.idleTimeoutMs, onIdle: "pause" | "stop", autoResume (sandboxes have only a TTL)
  • region
  • read-only volume mounts
  • renaming a secret through envVar
  • egress deny rules and inject
  • unknown GPU types

metadata has no Beam equivalent. getInfo() returns what this process created the sandbox with, and {} after connect().

Secrets and egress

Beam secrets are brokered. The sandbox only sees a placeholder, and Beam substitutes the real value in HTTPS headers sent to the hosts the secret allows. Create the secret with its host rules, then pass it by name:

beam secret create OPENAI_API_KEY "$OPENAI_API_KEY" --host api.openai.com
await client.create({ secrets: [{ name: "OPENAI_API_KEY", mode: "egress" }] });

network and sandbox.network.setEgressPolicy() map to blockNetwork / allowList (updateNetworkPermissions at runtime). Allow-lists take hostnames, *. wildcards, IPs and CIDRs, up to 64 entries. Hostname rules only apply to ports 443 and 80.

Previews

sandbox.ports.expose(port) returns Beam's public URL (https://<id>-<port>.app.beam.cloud). ports.list() maps to listUrls().

Beam sandbox URLs are always public (auth: { type: "public" }), so privatePreview is unsupported and previewBrowserAuth is false. Add authentication inside your app before exposing anything sensitive.

Snapshots and fork

  • snapshots.create() calls snapshot(), which captures memory and filesystem (includesMemory: true). Boot it with client.create({ fromSnapshot }). A memory checkpoint restores with its original configuration, so the rest of the spec is ignored.
  • snapshots.create({ mode: "filesystem" }) calls createImageFromFilesystem() and returns an image:<id> ref (includesMemory: false). Booting it applies the full spec on top of that image.
  • sandbox.fork({ count }) takes a memory snapshot and boots count sandboxes from it.

There is no in-place restore, and no API to list or delete snapshots.

Templates

client.templates.build() builds a Beam image in your workspace:

  • { dockerfile, context } runs Image.fromDockerfile. The Dockerfile and context are written to a temp directory, and Beam syncs that directory as the build context. This needs Node.
  • { image } runs Image.fromRegistry. registryAuth is passed as Docker Hub credentials.
  • env runs withEnvs. workdir and user become WORKDIR / USER lines.
  • startCmd / readyCmd throw Validation, because Beam sandboxes boot their own entrypoint.
const tpl = await client.templates!.build({
  source: {
    dockerfile: "FROM node:22-slim\nRUN npm i -g pnpm\n",
  },
});
const sandbox = await client.create({ template: tpl });

Beam images are content-addressed and have no name or tag. Before building, the adapter calls exists(), so an identical image is reused even from another process (status: "cached"). templates.get(id) resolves Beam image ids. A cache key only resolves in the process that built it. Build logs go to the SDK's own console output, and onEvent receives the status changes.

Code interpreter

sandbox.code.runCode(code) runs Python through runCode (non-blocking, so output streams to onStdout / onStderr). A non-zero exit is parsed into error (ValueError: ...). There is no stateful kernel, and other languages throw Validation.

Options

Prop

Type

Capabilities

CapabilityLevelNotes
streamingnativeper-process stdout/stderr streams, kept separate
backgroundnativeexec returns immediately; commands.connect reattaches by pid
killProcessnativelistProcesses() + process.kill()
codeInterpreternativePython runCode; no stateful kernel
egressControlnativeblockNetwork / allowList, updateNetworkPermissions
secretsVaultnativebrokered workspace secrets
exposePortnativepublic URLs; listUrls()
snapshot / forknativememory checkpoints; filesystem images
templateBuildnativedockerfile, image
setTimeoutnativeupdateTtl
gpunativeresources.gpu
filesUploadnativefs.writeBytes
listunsupportedBeam has no per-sandbox labels to filter by
volumes (registry)unsupportedthe SDK has only Volume.getOrCreate; mounting via spec.volumes works
pause / stopunsupporteddestroy() = terminate()
privatePreviewunsupportedsandbox URLs are public
pty / ssh / metrics / stdinunsupportednot in the sandbox API

Flags: perCommandEnvCwd: true, exitCodeNative: true, previewModel: "subdomain", templateSources: ["dockerfile", "image"].

Known limitations

  • Idempotency: Beam has no idempotency key or label lookup. A create() that fails after Beam accepted it can leave an orphaned sandbox, which expires at the end of its TTL.
  • Live state: getInfo() reads the workspace container list (GET /api/v1/gateway/containers). A sandbox missing from the list is reported as destroyed.
  • Files: the native filesystem API covers read, write, list, mkdir, remove and stat. rename falls back to mv over exec. Writes create missing parent directories.
  • stdin: buffered stdin is piped through the shell. There is no interactive writeStdin.
  • VMs: Beam's persistent VM API (pause/resume with memory, idle actions, SSH, desktop) is not wrapped yet. Use the VM class from @beamcloud/beam-js directly for now.

On this page