Skip to content

DigitalOcean.Sandboxes reference

Source: packages/digitalocean/src/Sandboxes/CreateSandbox.ts

Creates DigitalOcean MicroVM sandboxes at run time from a Sandboxes.Template, from a Worker, App, Lambda or any other host. Sandboxes boot from the template’s checkpoint, so they start with its packages installed.

DigitalOcean has no API to create access tokens, so the host cannot get a key of its own. Pass a token you created with only the microvm scopes as token; it reaches the host as a secret and is never your deploy token.

const Base = DigitalOcean.Sandboxes.Template("node", { image: "node:22-bookworm" });
export default class Api extends DigitalOcean.App<Api>()(
"Api",
{ main: import.meta.url },
Effect.gen(function* () {
const token = yield* Config.Redacted("SANDBOX_TOKEN");
const sandboxes = yield* DigitalOcean.Sandboxes.CreateSandbox(Base, { token });
return {
fetch: Effect.gen(function* () {
const sandbox = yield* Effect.acquireRelease(sandboxes.create(), (s) =>
Effect.ignore(s.delete),
);
const result = yield* sandbox.exec("node --version");
return HttpServerResponse.text(result.stdout);
}).pipe(Effect.orDie),
};
}).pipe(Effect.provide(DigitalOcean.Sandboxes.CreateSandboxHttp)),
) {}

Source: packages/digitalocean/src/Sandboxes/CreateSandboxHttp.ts Kind: Layer · Provides: DigitalOcean.Sandboxes.CreateSandbox

CreateSandbox over the DigitalOcean MicroVM API, signed with the token the binding was given.

Source: packages/digitalocean/src/Sandboxes/Sandbox.ts

A long-lived DigitalOcean MicroVM sandbox, started from a Sandboxes.Template or an OCI image: an isolated Linux VM for an agent, a dev environment, or untrusted code. Every prop replaces the sandbox. To create sandboxes per request instead, bind Sandboxes.CreateSandbox in a runtime.

const base = yield* DigitalOcean.Sandboxes.Template("node", { image: "node:22-bookworm" });
const sandbox = yield* DigitalOcean.Sandboxes.Sandbox("dev", {
base,
httpPort: 3000,
autoPauseSeconds: 600,
});
// sandbox.url serves port 3000 and resumes the VM on request.

Source: packages/digitalocean/src/Sandboxes/Template.ts

A sandbox base: a DigitalOcean MicroVM booted from an OCI image, set up with your commands, and checkpointed. Sandboxes created from it start in that exact state, with packages installed and caches warm, in well under a second. A new image or setup rebuilds the template, creating the new checkpoint before deleting the old one.

const base = yield* DigitalOcean.Sandboxes.Template("node-git", {
image: "node:22-bookworm",
setup: ["apt-get update", "apt-get install -y git"],
});
const sandbox = yield* DigitalOcean.Sandboxes.Sandbox("agent", { base });