Templates
A template is the starting point for a machine, everything it comes with already set up. Pick a ready-made one when you create a machine, or build your own so every sandbox or VM starts with exactly the tools you need.
Ready-made templates
Pass a template name to create. Sandboxes default to base; VMs default to the standard Ubuntu desktop.
const sbx = await sandboxes.create({ template: "base" }) // headless
const desk = await desktops.create({ template: "office" }) // GUIbase: the standard headless sandbox (the sandbox default).default/workstation: the standard Ubuntu desktop.office: desktop + LibreOffice, GIMP, Inkscape, a file manager and PDF viewer.code: desktop + developer tools (git, Python, Node) and VS Code in the browser.
Custom templates: bring your own setup
Build your own reusable template: start from a base and add the steps you want, then create machines from it. You get back a tpl_… id that belongs to your team. Every machine you start from it comes with your tools already installed, with no setup to wait for each time.
import { SandboxClient, TemplateClient, Image } from "@solarisdk/sandbox"
const opts = {
apiKey: process.env.SOLARI_API_KEY!,
baseUrl: "https://api.getsolari.com",
}
const templates = new TemplateClient(opts)
const sandboxes = new SandboxClient(opts)
// Describe what you want, one step at a time.
const image = Image.base("ubuntu:22.04")
.kind("sandbox") // "sandbox" (headless) or "desktop" (with a screen)
.aptInstall(["ffmpeg", "poppler-utils"])
.pipInstall(["pandas", "pdfplumber"])
.runCommands("mkdir -p /work")
.env({ HF_HOME: "/work/.hf" })
.workdir("/work")
// Build it and wait until it's ready to use.
const tpl = await templates.build(image, { name: "media-tools" })
// Create a machine from it, with everything already installed.
const sbx = await sandboxes.create({ template: tpl.templateId })Builder steps
Steps run in the order apt → pip → run → env → workdir:
aptInstall([...]): installed first, in oneapt-get install.pipInstall([...]):pip3 install --no-cache-dir.runCommands("…", "…"): one shell command per argument, in order.env({ KEY: "val" }): environment variables that stay set every time you start the machine.workdir("/work"): creates the folder and uses it as the working directory for later steps.
You can also start from an existing template instead of a plain OS with Image.fromTemplate("workstation"). Uploading files from your own computer (addLocalFile() / addLocalDir()) isn't supported yet; a recipe that uses it is turned away when you build.
Manage templates
await templates.list() // ready-made templates + your team's custom ones
await templates.get(tpl.templateId) // check its status: building | ready | failed
await templates.delete(tpl.templateId)sandbox template only works with sandboxes.create, and a desktop template only with desktops.create. Mixing them is turned away.Deleting
- A template that is still
buildingcan't be deleted yet, and ready-made templates can't be deleted either. - A
readytemplate can be deleted even while machines created from it are still running. Those machines keep working on their own and aren't affected. - Your custom templates stick around and stay ready to use until you delete them.
