RailwayBeta
Isolated Debian Linux VMs on Railway, with streaming exec, real kill, background sessions you can reattach to, native files, checkpoints, forks and preview domains.
Beta. Railway Sandboxes are a beta product, so the SDK surface may change.
The adapter targets the official railway SDK 3.4 or later (3.17
recommended). Versions below 3.0 were an unrelated package.
Installation
railway is an optional peer dependency of sbox-sdk. It's loaded lazily the first time you create or connect.
pnpm add sbox-sdk railwayAuthentication
An API token + environment id.
| Option | Env var | Required | Description |
|---|---|---|---|
token | RAILWAY_API_TOKEN | required | Railway API token. |
environmentId | RAILWAY_ENVIRONMENT_ID | required | Target environment id the sandboxes run in. |
networkIsolation | — | optional | Network isolation for new sandboxes ("ISOLATED" or "PRIVATE"). |
Token and environment id fall back to RAILWAY_API_TOKEN / RAILWAY_ENVIRONMENT_ID when the options are omitted.
The SDK reads credentials from the environment, so all options are optional:
RAILWAY_TOKEN: a project token. This is the recommended option, because the environment comes with the token.RAILWAY_API_TOKEN: an account or workspace token. It also needsRAILWAY_ENVIRONMENT_ID(or theenvironmentIdoption).
The adapter passes token, authType, environmentId and endpoint through to every SDK call: create, connect, list, checkpoints and verify.
Usage
import { createSandboxClient } from "sbox-sdk";
import { railway } from "sbox-sdk/railway";
const client = createSandboxClient({
provider: railway({
token: process.env.RAILWAY_TOKEN, // or RAILWAY_API_TOKEN + environmentId
}),
});
const sandbox = await client.create({
env: { NODE_ENV: "production" },
resources: { vcpus: 2, memoryMB: 4096 },
region: "us-west2",
lifecycle: { idleTimeoutMs: 15 * 60_000 }, // destroyed after 15 idle minutes
metadata: { team: "agents" },
});
// exec streams live, and stdout and stderr stay separate.
for await (const ev of sandbox.commands.run("npm install", { cwd: "/app" })) {
if (ev.type === "stdout") process.stdout.write(ev.data);
}
// Background processes are durable sessions you can reattach to.
const server = await sandbox.commands.spawn("node server.js");
const again = await sandbox.commands.connect(server.id); // replays output
await sandbox.commands.kill(server.id, "SIGTERM");
await sandbox.files.write("/work/data.bin", new Uint8Array([1, 2, 3]));
await sandbox.destroy();Templates, checkpoints and forks
On Railway, template is not a container image. It's the name of a checkpoint: a saved disk you boot from. Every sandbox starts from Railway's Debian base.
// Save the current disk as a named checkpoint...
const snap = await sandbox.snapshots!.create({ name: "deps-installed" });
// ...and boot new sandboxes from it. `template: "deps-installed"` is equivalent.
const copy = await client.create({ fromSnapshot: snap });
await sandbox.snapshots!.list(); // every checkpoint in the environment
await sandbox.snapshots!.delete(snap); // looked up by key, deleted by id
const [child] = await sandbox.fork(); // clones the filesystem (a fresh boot)Checkpoints capture the disk only (includesMemory: false). Restoring one boots a new sandbox, so in-place snapshots.restore() is not available.
Building a base: the native recipe builder
Railway has no Dockerfile or registry-image build, so templateBuild is unsupported and client.templates is undefined. Instead, Railway builds bases from a recipe, Sandbox.template(), and caches the result by recipe hash. To use one, pass it to the factory. It applies to every create that doesn't name a template or fromSnapshot:
import { Sandbox } from "railway";
import { railway } from "sbox-sdk/railway";
const base = Sandbox.template()
.withPackages("git", "python3")
.run("pip install uv")
.workdir("/app");
const provider = railway({ template: base }); // built once, then cachedPreviews
Railway publishes HTTP domains at create time. To get one, declare its ports in spec.ports. Domains need the sandbox on the environment's private network, so you must opt in with networkIsolation: "PRIVATE":
const client = createSandboxClient({
provider: railway({ networkIsolation: "PRIVATE" }),
});
const sandbox = await client.create({ ports: [3000] });
const preview = await sandbox.ports!.expose(3000); // { url, wsUrl, auth: { type: "public" } }Some limits apply:
- Domains are public. There are no private previews, so
privatePreviewis unsupported andpreviewBrowserAuthisfalse. expose()of a port you didn't declare throwsValidation.unexpose()is not available.
Secrets
An env-mode SecretRef that has no value becomes a Railway reference to the environment's shared variables. Railway resolves it inside the sandbox, so the value never passes through your process:
await client.create({
secrets: [
{ name: "OPENAI_API_KEY" }, // -> ${{shared.OPENAI_API_KEY}}
{ name: "db", envVar: "DB_PASSWORD", value: "inline" },
],
});Egress-mode (mode: "egress") secrets are not supported.
Options
Prop
Type
Capabilities
| Capability | Level | Notes |
|---|---|---|
streaming | native | onStdout / onStderr, stderr kept separate |
background | native | durable exec sessions; commands.connect(id) reattaches |
killProcess | native | ExecHandle.kill(signal) to the process group |
stdin | native | spawn() opens stdin (process.writeStdin) |
filesUpload | native | streaming files.write / files.read({ format: "stream" }) |
list | native | see limitations |
snapshot | native | named checkpoints (disk only) |
fork | native | clones the filesystem |
exposePort | native | declaredPorts: domains from spec.ports |
region | native | spec.region |
secretsVault | native | ${{shared.NAME}} references |
privatePreview | unsupported | domains are public |
egressControl | unsupported | ISOLATED = public NAT egress; no filtering |
pause / stop | unsupported | destroy() tears the VM down |
setTimeout | unsupported | the idle timeout is fixed at create |
templateBuild | unsupported | use the native recipe builder (above) |
pty / ssh / metrics | unsupported | |
volumes / gpu | unsupported | |
codeInterpreter | unsupported |
perCommandEnvCwd is true, because exec takes cwd/env natively. timeoutMs maps to the SDK's timeoutSec.
How the spec maps
| sbox | Railway |
|---|---|
template / fromSnapshot | Sandbox.create(checkpointName, …) |
env | env (Railway references allowed) |
resources.vcpus / memoryMB | resources.cpu / resources.memoryGB (decimal GB) |
region | region |
lifecycle.idleTimeoutMs | idleTimeoutMinutes (rounded up; idle sandboxes are destroyed) |
ports | domains (needs networkIsolation: "PRIVATE") |
metadata / name | JSON file at /etc/sbox/metadata.json in the sandbox |
idempotencyKey | stored in the same file; a retried create reuses the sandbox |
The following settings throw Validation:
lifecycle.maxAgeMs(Railway has no wall-clock limit)onIdle: "pause" | "stop"- a
networkpolicy other thanallow-all volumesresources.gpu
diskMB and shmMB are ignored.
Known limitations
- No native labels.
metadataandnamelive in a small file inside the sandbox. SogetInfo()andlist()read that file for running sandboxes (cached per process), andlist()costs one connect and one read for each running sandbox it hasn't seen yet. Sandboxes that aren't running report empty metadata. list()returns one page. The SDK'sSandbox.list()exposes no cursor, so the adapter can't paginate beyond the server's default page.snapshots.list()is environment-wide. Railway checkpoints don't record their source sandbox. The list also includes the checkpoints that recipe builds produce, keyed by recipe hash.- No runtime TTL changes. To reset the idle countdown, use
sandbox.raw().heartbeat(). - Foreground
commands.run()has nowriteStdin. Its stdin closes immediately. Usespawn()for interactive input. Bufferedstdinin options works everywhere.
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.
Northflank
A sandbox per Northflank deployment service, driven through @northflank/js-client. Streaming exec, PTYs, container snapshots, GPUs and metrics.