Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions crates/spawn-api/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1709,11 +1709,10 @@ mod tests {
Ok(spec)
}

#[test]
fn repo_templates_are_valid() {
let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../templates");
fn check_templates_dir(rel: &str) -> usize {
let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join(rel);
let mut count = 0;
for entry in std::fs::read_dir(dir).unwrap() {
for entry in std::fs::read_dir(&dir).unwrap() {
let path = entry.unwrap().path();
if path.extension().is_some_and(|ext| ext == "json") {
let spec = template(&std::fs::read_to_string(&path).unwrap())
Expand All @@ -1725,7 +1724,17 @@ mod tests {
count += 1;
}
}
assert!(count > 0);
count
}

#[test]
fn repo_templates_are_valid() {
assert!(check_templates_dir("../../templates") > 0);
}

#[test]
fn example_templates_are_valid() {
assert!(check_templates_dir("../../templates/examples") >= 4);
}

#[test]
Expand Down
31 changes: 31 additions & 0 deletions templates/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Example Templates

Ready-to-customize Spawnbox `TemplateSpec` files for common sandbox workloads.
Unlike the coding agent templates directly in `templates/`, these examples are
not auto-built by `deploy/install.sh`; build only the ones you need.

| File | Template name | Base image | Resources | Purpose |
| --- | --- | --- | --- | --- |
| `browser-playwright.json` | `browser-playwright` | `node:26-bookworm-slim` | 2 vCPU, 2048 MiB, 20 GiB | Headless Chromium + Playwright on Node.js 26 (non-root safe) |
| `web-app.json` | `web-app` | `node:26-bookworm-slim` | 2 vCPU, 2048 MiB, 20 GiB | Node.js 26 + pnpm runtime for Next.js, Vite, or Express services |
| `mcp-server.json` | `mcp-server` | `node:26-bookworm-slim` | 2 vCPU, 1024 MiB, 10 GiB | Node.js 26 (`tsx`) + Python 3 (`mcp`, `uvicorn`) for Streamable HTTP MCP servers |
| `python-data.json` | `python-data` | `python:3.12-slim-bookworm` | 2 vCPU, 2048 MiB, 10 GiB | Python 3.12 virtualenv with `numpy`, `pandas`, and headless `matplotlib` |

## Usage

Build a template with the Spawnbox CLI:

```sh
spawnbox templates build templates/examples/browser-playwright.json
```

Check build status, then create a sandbox from the template:

```sh
spawnbox templates ls
spawnbox create --template browser-playwright
```

To customize a template (for example, adding your own packages, pinning a
container image digest, or tuning `resources`), copy the file, edit `name` and
`setup`, and pass it to `spawnbox templates build`.
14 changes: 14 additions & 0 deletions templates/examples/browser-playwright.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "browser-playwright",
"base": "node:26-bookworm-slim",
"setup": [
"npm install -g --no-fund --no-audit playwright@1.52.0",
"PLAYWRIGHT_BROWSERS_PATH=/opt/ms-playwright playwright install --with-deps chromium && chmod -R a+rX /opt/ms-playwright && rm -rf /var/lib/apt/lists/*"
],
"warmup": ["playwright --version"],
"env": {
"NODE_PATH": "/usr/local/lib/node_modules",
"PLAYWRIGHT_BROWSERS_PATH": "/opt/ms-playwright"
},
"resources": {"vcpus": 2, "memory_mib": 2048, "disk_gib": 20}
}
19 changes: 19 additions & 0 deletions templates/examples/mcp-server.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "mcp-server",
"base": "node:26-bookworm-slim",
"setup": [
"apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends python3 python3-pip python3-venv git ca-certificates && rm -rf /var/lib/apt/lists/*",
"python3 -m venv /opt/mcp-venv && /opt/mcp-venv/bin/pip install --no-cache-dir mcp==1.9.4 uvicorn==0.34.3",
"npm install -g --no-fund --no-audit tsx@4.19.4"
],
"warmup": [
"node --version",
"python3 --version",
"/opt/mcp-venv/bin/python -c 'import mcp'"
],
"env": {
"PATH": "/opt/mcp-venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"VIRTUAL_ENV": "/opt/mcp-venv"
},
"resources": {"vcpus": 2, "memory_mib": 1024, "disk_gib": 10}
}
15 changes: 15 additions & 0 deletions templates/examples/python-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "python-data",
"base": "python:3.12-slim-bookworm",
"setup": [
"python3 -m venv /opt/venv",
"/opt/venv/bin/pip install --no-cache-dir numpy==2.2.6 pandas==2.2.3 matplotlib==3.10.3"
],
"warmup": ["/opt/venv/bin/python -c 'import numpy, pandas, matplotlib'"],
"env": {
"MPLBACKEND": "Agg",
"PATH": "/opt/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"VIRTUAL_ENV": "/opt/venv"
},
"resources": {"vcpus": 2, "memory_mib": 2048, "disk_gib": 10}
}
14 changes: 14 additions & 0 deletions templates/examples/web-app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "web-app",
"base": "node:26-bookworm-slim",
"setup": [
"apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends git ca-certificates && rm -rf /var/lib/apt/lists/*",
"npm install -g --no-fund --no-audit pnpm@10.11.0"
],
"warmup": ["node --version", "pnpm --version"],
"env": {
"NEXT_TELEMETRY_DISABLED": "1",
"NODE_ENV": "production"
},
"resources": {"vcpus": 2, "memory_mib": 2048, "disk_gib": 20}
}
Loading