Skip to content

Templates

A template is defined in code and built by the platform. Every sandbox created from it boots that image in milliseconds. The build is cached step by step, so a rebuild that changes the last step reruns only that step.

from svm import Sandbox, SandboxClient, Template
template = (
Template("docs-fastapi", client=SandboxClient())
.from_python_image("3.12")
.pip_install(["fastapi", "uvicorn"])
.set_envs({"APP_ENV": "docs"})
.set_ready_cmd("python3 -c 'import fastapi'")
)
# on_log follows the build to its end and raises BuildError if it fails.
build = template.build(on_log=lambda line: print(line.stream, line.line))
print("build", build.id, build.info.status)
with Sandbox.create(template="docs-fastapi") as sandbox:
result = sandbox.commands.run("python3 -c 'import fastapi; print(fastapi.__version__)'")
print(result.stdout, sandbox.commands.run("echo $APP_ENV").stdout)
Helper What it does
from_image(ref), from_python_image("3.12"), from_node_image, from_ubuntu_image, from_debian_image, from_alpine_image Choose the base image
from_catalog_template("python") Start from a platform catalog template instead of an image
from_dockerfile(text) Import a Dockerfile
apt_install, pip_install, npm_install, bun_install Install packages. apt_install uses the base image’s own package manager.
copy, copy_items, make_dir, make_symlink, remove, rename Files
git_clone(url, path, branch=, depth=) Clone a public HTTPS repository
set_envs, set_workdir, set_user, set_default_user Runtime defaults
set_start_cmd, set_ready_cmd A process to start, and the check that says the sandbox is ready
add_mcp_server Turn on an MCP server for every sandbox of the template
skip_cache Force a fresh build

Ready-check helpers return the shell text that set_ready_cmd takes: wait_for_port(8080), wait_for_url(url), wait_for_process("nginx"), wait_for_file(path) and wait_for_timeout(ms).

Pass registry_secret to from_image with the name of a team secret that holds user:password. For Google Artifact Registry, use from_gcp_registry(ref, secret) with a _json_key:<key JSON> secret.

From the CLI: svm template build, svm template list, svm template publish --tag.