An open-source, faster Devin alternative
TypeScript
docs: templates page leads with the contract being unchanged rather than offering a choice — there is one templates path in the API (define by name with Image, create with template:), so presenting 'workspace templates' vs 'custom images' invented a decision customers cannot make and named an internal mechanism they never see; the page now states the API is the same as v1 and covers only what is actually visible to them: build ahead of time, template creates cold-start, AL2023/ARM64 package and architecture caveats, the 10-per-org cap, and rebuilding v1 rootfs templates
Brian Reardon0688ade47e3d
diff --git a/docs/migrating-from-v1.mdx b/docs/migrating-from-v1.mdxindex cd288571..9dd4deca 100644--- a/docs/migrating-from-v1.mdx+++ b/docs/migrating-from-v1.mdx@@ -88,7 +88,8 @@ A v1 template captures the whole disk. v2 can only replay the workspace half, ansilently would hand you your files while dropping every system change the template existed for.So it refuses, loudly, at create.-Rebuild affected templates as workspace templates or checkpoints on v2.+Rebuild them on v2 — usually by re-running the same `Image` definition under the same name.+See [Templates](/sandboxes/templates).### Sizes are fixed steps, and 16 GB is gonediff --git a/docs/sandboxes/templates.mdx b/docs/sandboxes/templates.mdxindex 8b67feb7..8afe70c4 100644--- a/docs/sandboxes/templates.mdx+++ b/docs/sandboxes/templates.mdx@@ -1,45 +1,10 @@---title: "Templates"-description: "Two ways to prepare an environment, and which one you need"+description: "Same API as v1, with two differences worth knowing"----A template is an environment prepared once and reused by many sandboxes. v2 has **two-mechanisms**, and which one you need depends on a single question: does your setup write-outside the home directory?--| Your setup | Mechanism | Create speed |-| --- | --- | --- |-| Python/Node packages, files, env vars | **Workspace template** | Full pooled speed |-| System packages (`apt`/`dnf`), anything in `/usr` | **Custom image** | Cold start, a few seconds |--If a workspace template covers you, use it — it is faster at create time and has no limits-worth worrying about.--## Workspace templates--A workspace template claims a standard pooled sandbox and unpacks your saved workspace on top-of it. You keep the fast pooled create, and the template costs nothing but a tarball.--```typescript-const sandbox = await Sandbox.create({ templateID: "my-template" });-```--This captures **everything under your home directory**. That is more than it sounds: `pip` and-`npm` are configured to install there, so a Python or Node toolchain is captured for free.--```typescript-// Both of these are captured by a workspace template.-await sandbox.exec.run("pip install pandas");-await sandbox.exec.run("npm install -g typescript");-```--What it does **not** capture is anything outside your home directory — `dnf install` writing to-`/usr`, system services, files in `/etc`. For those you need a custom image.--## Custom images--A custom image bakes your setup into the machine image the sandbox boots from, so system-level-changes persist. You define it with the same `Image` builder v1 uses:+Templates work on v2, and **the contract is unchanged**. You define an environment once,+give it a name, and start sandboxes from that name:```typescriptimport { Image, Snapshots, Sandbox } from "@opencomputer/sdk";@@ -53,83 +18,87 @@ await snapshots.create({.pipInstall(["numpy"]),});-// Building takes minutes — wait for it before using it.await snapshots.waitUntilReady("video-tools");const sandbox = await Sandbox.create({ template: "video-tools" });```-### Four things to know--<Warning>-**Builds take minutes, not seconds.** The image is built by the platform, not in your sandbox.-Build once, then start as many sandboxes from it as you like.-</Warning>+Same `Image` builder, same names, same `list` / `get` / `delete`. Your existing definitions+carry over as written — what changes is how they are built underneath, and two consequences of+that are visible to you.-**Sandboxes from a custom image cold-start.** The warm pool holds standard sandboxes, so a-custom-image create takes a few seconds instead of milliseconds. If create latency matters more-than system packages, prefer a workspace template.+## 1. Build ahead of time-**The base is Amazon Linux 2023, not Ubuntu.** `aptInstall` still works — package names are-translated where they differ (`build-essential` becomes `gcc gcc-c++ make`) — but a package that-exists only on Debian will fail the build, and the error names the package.+A template is built into a machine image before any sandbox uses it, which takes minutes rather+than seconds. So the build is a separate step from the create, and you wait for it once:-**Everything runs on ARM64.** A build step that downloads an x86-64 binary will fail. Use your-package manager, or fetch the `aarch64`/`arm64` build.+```typescript+await snapshots.create({ name: "tools", image });+await snapshots.waitUntilReady("tools"); // minutes, once+await Sandbox.create({ template: "tools" }); // fast, every time after+```-### Limits+<Warning>+Passing `image:` directly to `Sandbox.create()` is refused on v2. A create that waited for a+build would time out, so the error names the two-step path instead of returning a sandbox+without your packages.+</Warning>-Custom images are a limited resource, so each org can hold **10** at a time. Delete one you are-no longer using to make room.+## 2. Sandboxes from a template cold-start-Two identical definitions share a single image, so rebuilding an unchanged template costs-nothing and returns immediately.+Standard sandboxes come from a warm pool. A sandbox built on your template does not, because the+pool holds standard sandboxes — so expect a few seconds rather than milliseconds on create.-## Building inline is not supported+Everything the template installed is already baked in, so this is paid at create, not on your+first command.-<Warning>-Passing `image:` directly to `Sandbox.create()` is refused on v2. Create the image first, then-create sandboxes from it by name.-</Warning>+## What your definitions run on-A build takes minutes; a create that waited for one would time out. The refusal names the-supported path rather than quietly handing you a sandbox without your packages.+The environment underneath is Amazon Linux 2023 on ARM64, so two things in an existing+definition can need attention:-```typescript-// Refused on v2-await Sandbox.create({ image: Image.base().aptInstall(["ffmpeg"]) });+<CardGroup cols={2}>+ <Card title="Package names" icon="box">+ `aptInstall` works and common Debian names are translated — `build-essential` becomes+ `gcc gcc-c++ make`. A package that exists only on Debian fails the build, and the error+ names it.+ </Card>+ <Card title="Architecture" icon="microchip">+ A step that downloads an x86-64 binary fails. Use your package manager, or fetch the+ `aarch64` build.+ </Card>+</CardGroup>-// Do this instead-await snapshots.create({ name: "tools", image: Image.base().aptInstall(["ffmpeg"]) });-await snapshots.waitUntilReady("tools");-await Sandbox.create({ template: "tools" });-```+Each org holds up to **10** templates at a time; delete one to make room. Two identical+definitions share one build, so rebuilding an unchanged template returns immediately.-## Migrating a v1 template+## Templates built on v1<Warning>A template that carries a **rootfs image** cannot be used on v2. The create fails with*"template … carries a rootfs image, which v2 cannot restore."*</Warning>-v1 templates capture the whole disk. v2 cannot replay that, and replaying only the workspace half-would hand you your files while dropping every system change the template existed for — a-template that looks like it worked and hasn't. So it refuses instead.+v1 templates capture the whole disk. Replaying only part of that would hand you your files while+dropping every system change the template existed for — a template that looks like it worked and+hasn't — so it refuses instead.++Rebuilding is the fix, and usually means re-running the `Image` definition you already have.<Steps><Step title="Try each template">- A template that cannot be used fails loudly at create with the message above. That is the- fastest audit — nothing to inspect.+ One that cannot be used fails loudly at create with the message above. That is the fastest+ audit — nothing to inspect.</Step>- <Step title="Rebuild it in the right place">- Packages installed into your home directory become a workspace template. System packages- become a custom image, using the same `Image` definition you already have.+ <Step title="Rebuild it">+ Create it again by name with the same definition, wait for the build, and point your creates+ at it.</Step></Steps><CardGroup cols={2}><Card title="Checkpoints" icon="camera" href="/sandboxes/checkpoints">- Save a running sandbox's workspace and restore it later.+ Save a running sandbox and restore it later.</Card><Card title="Migrating from v1" icon="arrow-right" href="/migrating-from-v1">Every behaviour that differs between v1 and v2.