Getting started
Run a command in a sandbox from your own TypeScript application. You’ll need a provider account and Bun to run this example. The SDK also supports server-side Node.js.
1. Install
Section titled “1. Install”In your project, install the SDK and the adapter for your provider:
npm install beachside @beachside/boxdnpm install beachside @beachside/freestylenpm install beachside @beachside/daytonanpm install beachside @beachside/e2bnpm install beachside @beachside/archilnpm install beachside @beachside/boatnpm install beachside @beachside/runloopnpm install beachside @beachside/exe-devnpm install beachside @beachside/vercelThe Modal adapter is not published to npm. Run it from a source checkout with Bun 1.4.4:
git clone https://github.com/beachside-compute/beachside.gitcd beachsidebun install --frozen-lockfilebun run build:packagespnpm add and bun add work too. Compare provider support before choosing.
To run OpenCode rather than a shell command, use the OpenCode recipe.
2. Add your credentials
Section titled “2. Add your credentials”Create an untracked .env.local file in your project root (the repository root for Modal):
BOXD_API_KEY="<your-boxd-api-key>"BOXD_ORG="<your-org-id-or-slug>"BOXD_ORG is the ID (org-…) of the org your key belongs to; boxd auth --json lists your orgs with their IDs. The example uses boxd’s default image with internet access; set network: "blocked" or an allowlist to restrict it.
FREESTYLE_API_KEY="<your-freestyle-api-key>"The example uses Freestyle’s default VM image with internet access.
DAYTONA_API_KEY="<your-daytona-api-key>"The example uses the daytona-small Linux snapshot in us. Select an active snapshot available in your region. daytona-default permits Daytona’s essential services; it does not mean all egress is blocked.
E2B_API_KEY="<your-e2b-api-key>"The example uses E2B’s public base template. No team ID or custom template is required.
ARCHIL_API_KEY="<your-archil-api-key>"Create an API key in the Archil console. The example runs in aws-us-east-1 (the others are aws-us-west-2 and aws-eu-west-1) with internet access, which needs a paid Archil plan. On the Free plan, add network: "archil-managed" to config.
BOAT_API_KEY="<your-boat-api-key>"Create an API key in the Boat dashboard. The example starts a full Ubuntu VM with internet access.
RUNLOOP_API_KEY="<your-runloop-api-key>"Create an API key in the Runloop dashboard; sign-ups are by invitation. The example uses the default Devbox image with internet access.
EXE_API_KEY="<your-exe-dev-token>"Create a token with ssh exe.dev token (see API tokens). exe.dev VMs have internet egress.
VERCEL_TOKEN="<your-vercel-token>"VERCEL_TEAM_ID="<your-team-id>"VERCEL_PROJECT_ID="<your-project-id>"Use an existing Vercel team and project. The example uses Vercel’s default Node image with internet access.
MODAL_TOKEN_ID=your-modal-token-idMODAL_TOKEN_SECRET=your-modal-token-secretMODAL_APP_NAME=your-existing-appMODAL_IMAGE_ID=im-your-existing-image-idUse an existing Modal App in the main environment and an existing prepared image containing /bin/sh and standard shell utilities. The example does not create an App or build an image.
Add .env.local to your .gitignore. Keep credentials on the server and out of browser code. Running the example creates a sandbox in your provider account and may incur usage charges.
3. Run a command
Section titled “3. Run a command”Choose a provider and save the example as quickstart.ts:
import { Beachside } from "beachside";import { boxdAdapter } from "@beachside/boxd";
const apiKey = process.env.BOXD_API_KEY;
const org = process.env.BOXD_ORG;
if (!apiKey || !org) throw new Error("Set BOXD_API_KEY and BOXD_ORG before running this example");
const beachside = await Beachside.connect({ adapter: boxdAdapter, credentials: { apiKey }, config: { org },});
try { await beachside.sandboxes.with({}, async (box) => { const output = await box.exec(["printf", "Hello from Beachside!\n"]); console.log(output.stdoutText()); });} finally { await beachside.close();}import { Beachside } from "beachside";import { freestyleAdapter } from "@beachside/freestyle";
const apiKey = process.env.FREESTYLE_API_KEY;
if (!apiKey) throw new Error("Set FREESTYLE_API_KEY before running this example");
const beachside = await Beachside.connect({ adapter: freestyleAdapter, credentials: { apiKey }, config: {},});
try { await beachside.sandboxes.with({}, async (box) => { const output = await box.exec(["printf", "Hello from Beachside!\n"]); console.log(output.stdoutText()); });} finally { await beachside.close();}import { Image, Beachside } from "beachside";import { daytonaAdapter } from "@beachside/daytona";
const apiKey = process.env.DAYTONA_API_KEY;
if (!apiKey) throw new Error("Set DAYTONA_API_KEY before running this example");
const beachside = await Beachside.connect({ adapter: daytonaAdapter, credentials: { apiKey }, config: { target: "us", environment: Image.prepared("daytona-small"), lifecycle: { lifetimeSeconds: 900 }, network: "daytona-default", },});
try { await beachside.sandboxes.with({}, async (box) => { const output = await box.exec(["printf", "Hello from Beachside!\n"]); console.log(output.stdoutText()); });} finally { await beachside.close();}import { Beachside } from "beachside";import { e2bAdapter } from "@beachside/e2b";
const apiKey = process.env.E2B_API_KEY;
if (!apiKey) throw new Error("Set E2B_API_KEY before running this example");
const beachside = await Beachside.connect({ adapter: e2bAdapter, credentials: { apiKey }, config: {},});
try { await beachside.sandboxes.with({}, async (box) => { const output = await box.exec(["printf", "Hello from Beachside!\n"]); console.log(output.stdoutText()); });} finally { await beachside.close();}import { Beachside } from "beachside";import { archilAdapter } from "@beachside/archil";
const apiKey = process.env.ARCHIL_API_KEY;
if (!apiKey) throw new Error("Set ARCHIL_API_KEY before running this example");
const beachside = await Beachside.connect({ adapter: archilAdapter, credentials: { apiKey }, config: { region: "aws-us-east-1" },});
try { await beachside.sandboxes.with({}, async (box) => { const output = await box.exec(["printf", "Hello from Beachside!\n"]); console.log(output.stdoutText()); });} finally { await beachside.close();}import { Beachside } from "beachside";import { boatAdapter } from "@beachside/boat";
const apiKey = process.env.BOAT_API_KEY;
if (!apiKey) throw new Error("Set BOAT_API_KEY before running this example");
const beachside = await Beachside.connect({ adapter: boatAdapter, credentials: { apiKey }, config: {},});
try { await beachside.sandboxes.with({}, async (box) => { const output = await box.exec(["printf", "Hello from Beachside!\n"]); console.log(output.stdoutText()); });} finally { await beachside.close();}import { Beachside } from "beachside";import { runloopAdapter } from "@beachside/runloop";
const apiKey = process.env.RUNLOOP_API_KEY;
if (!apiKey) throw new Error("Set RUNLOOP_API_KEY before running this example");
const beachside = await Beachside.connect({ adapter: runloopAdapter, credentials: { apiKey }, config: {},});
try { await beachside.sandboxes.with({}, async (box) => { const output = await box.exec(["printf", "Hello from Beachside!\n"]); console.log(output.stdoutText()); });} finally { await beachside.close();}import { Beachside } from "beachside";import { exeDevAdapter } from "@beachside/exe-dev";
const token = process.env.EXE_API_KEY;
if (!token) throw new Error("Set EXE_API_KEY before running this example");
const beachside = await Beachside.connect({ adapter: exeDevAdapter, credentials: { token }, config: {},});
try { await beachside.sandboxes.with({}, async (box) => { const output = await box.exec(["printf", "Hello from Beachside!\n"]); console.log(output.stdoutText()); });} finally { await beachside.close();}import { Beachside } from "beachside";import { vercelAdapter } from "@beachside/vercel";
const token = process.env.VERCEL_TOKEN;
const teamId = process.env.VERCEL_TEAM_ID;
const projectId = process.env.VERCEL_PROJECT_ID;
if (!token || !teamId || !projectId) throw new Error( "Set VERCEL_TOKEN, VERCEL_TEAM_ID and VERCEL_PROJECT_ID before running this example", );
const beachside = await Beachside.connect({ adapter: vercelAdapter, credentials: { token }, config: { teamId, projectId },});
try { await beachside.sandboxes.with({}, async (box) => { const output = await box.exec(["printf", "Hello from Beachside!\n"]); console.log(output.stdoutText()); });} finally { await beachside.close();}import { Image, Beachside } from "beachside";import { modalAdapter } from "@beachside/modal";
const tokenId = process.env.MODAL_TOKEN_ID;
const tokenSecret = process.env.MODAL_TOKEN_SECRET;
const appName = process.env.MODAL_APP_NAME;
const imageId = process.env.MODAL_IMAGE_ID;
if (!tokenId || !tokenSecret || !appName || !imageId) throw new Error("Set MODAL_TOKEN_ID, MODAL_TOKEN_SECRET, MODAL_APP_NAME, and MODAL_IMAGE_ID");
const beachside = await Beachside.connect({ adapter: modalAdapter, credentials: { tokenId, tokenSecret }, config: { appName, environment: "main", lifecycle: { lifetimeSeconds: 300 } },});
try { const box = await beachside.sandboxes.create({ environment: Image.prepared(imageId), });
try { const output = await box.exec(["/bin/sh", "-c", "printf 'Hello from Beachside!\n'"]); console.log(output.stdoutText()); } finally { await box.destroy(); }} finally { await beachside.close();}Run it with Bun:
bun --env-file=.env.local run quickstart.tsbun --env-file=.env.local run quickstart.tsbun --env-file=.env.local run quickstart.tsbun --env-file=.env.local run quickstart.tsbun --env-file=.env.local run quickstart.tsbun --env-file=.env.local run quickstart.tsbun --env-file=.env.local run quickstart.tsbun --env-file=.env.local run quickstart.tsFrom the repository root:
bun --env-file=.env.local run apps/docs/examples/getting-started-modal.tsYou should see Hello from Beachside!. Every example except Modal uses sandboxes.with() to clean up the sandbox after the callback succeeds or throws. An outer finally closes the client. The experimental Modal example shows manual sandbox cleanup. close() alone does not destroy compute. If creation or cleanup has an uncertain outcome, follow Errors and recovery before retrying.
For temporary work, prefer scoped sandbox cleanup. The scope retains snapshots and volumes, and cleanup failures preserve the callback result or error plus recovery information. Use manual create() when the sandbox should outlive the callback.
Next steps
Section titled “Next steps”-
Run OpenCode inside a sandbox to capture a response or edit a remote file, or browse the other recipes.
-
Give your agent a Beachside prompt to start building an application.
-
Check tested provider support for live-tested workflows and limits.
Bound connection waits
Section titled “Bound connection waits”Beachside.connect(adapter, { signal, timeoutMs: 30_000 }) accepts ConnectOptions.
The advanced definition/config/credentials form accepts the same controls in its options object.
await client.close({ signal: cleanupSignal, timeoutMs: 5_000 }) accepts CloseOptions.
Only positive finite safe-integer budgets are accepted; longer budgets are allowed.
Compatibility change: setup now defaults to a 30-second local wait and each close call defaults to a 5-second local wait. These budgets do not change sandbox lifetime, command deadlines or remote compute. Setup cancellation reports WAIT_ABORTED; expiry reports TIMEOUT, with effect none, cause and a phase-specific message. Aborting the setup signal after the client returns has no effect on the usable client.
Close immediately prevents new work and starts local cleanup once. Cancelling or timing out one close wait leaves that attempt running; a later close can wait for it. Cleanup runs in reverse registration order. A hanging hook can leave later hooks pending; failed releases are sent to onDiagnostic and remaining cleanup continues. Successful close means registered cleanup was attempted, not that every failed release succeeded. Late resources from abandoned setup are released locally. Neither setup failure nor close deletes sandboxes, volumes or snapshots; use explicit resource operations for those actions.
© 2026 Beachside Compute · Made by humans & in Texas