A template is a named environment that a sandbox can start from. Use one when many sandboxes need the same tools, settings and processes.
Not available yet.
Not available yet.
Not available yet.
import { Sutra } from "@mistrive/sutra";
const sutra = new Sutra({
baseUrl: "https://anchor.jgcp.mistrivedev.com",
});
const template = await sutra.templates.create({ id: "python-web", displayName: "Python web" });
// A version is immutable. Build it from an OCI image and give it defaults.
const version = await template.versions.create({
source: { image: "docker.io/library/python:3.12" },
defaults: {
resources: { milliCpus: 2000, memoryBytes: 4 * 1024 ** 3 },
ports: [{ port: 8000 }],
processes: { web: { argv: ["python3", "-m", "http.server", "8000"] } },
},
});
// Use the template name for its latest version, or pin one version.
const sandbox = await sutra.sandboxes.create({ source: { template: version.name } });
console.log(sandbox.state);from mistrive.sutra import Sutra
sutra = Sutra(
base_url="https://anchor.jgcp.mistrivedev.com",
)
template = sutra.templates.create(id="python-web", display_name="Python web")
# A version is immutable. Build it from an OCI image and give it defaults.
version = template.versions.create(
source={"image": "docker.io/library/python:3.12"},
defaults={
"resources": {"milli_cpus": 2000, "memory_bytes": 4 * 1024**3},
"ports": [{"port": 8000}],
"processes": {"web": {"argv": ["python3", "-m", "http.server", "8000"]}},
},
)
# Use the template name for its latest version, or pin one version.
sandbox = sutra.sandboxes.create(source={"template": version.name})
print(sandbox.state)#!/usr/bin/env bash
set -euo pipefail
# Assumes you ran `sutra auth login` (see the Quickstart).
sutra templates create python-web --display-name "Python web"
# A version is immutable. Build it from an OCI image and give it defaults.
sutra templates versions create python-web --id v1 \
--image docker.io/library/python:3.12 \
--port 8000 \
--process "web=python3 -m http.server 8000"
# Use the template name for its latest version, or pin one version.
sutra sandboxes create demo --template python-web/versions/v1Versions
A template has versions, and a version never changes. To change a template, create a new version. Sandboxes that already run keep the version they started from.
You build a version from one of two sources:
- An OCI image, such as
docker.io/library/python:3.12. - A snapshot of a sandbox you set up by hand.
Defaults
A version carries defaults for every sandbox started from it:
- Resources: CPU, memory and disk.
- Environment variables.
- Ports and volumes.
- A lifecycle policy, within your organization’s limits.
- Processes to start when the sandbox boots, by name.
Values you pass when you create a sandbox override the defaults.
Start a sandbox from a template
Set source.template when you create a sandbox. Pass the template’s name to use its latest version, or a version’s name to pin it.
For a quick start without a template, set source.image to an OCI image instead. Sutra builds it once and reuses the build for every sandbox with the same image digest.
Built-in templates
Sutra has a catalog of built-in templates for common environments. They are read-only and shared by every project, so you can use them without creating anything. A sandbox created without a source starts from the default built-in template.