diff --git a/crates/spawn-api/src/model.rs b/crates/spawn-api/src/model.rs index 2bad00d..285b127 100644 --- a/crates/spawn-api/src/model.rs +++ b/crates/spawn-api/src/model.rs @@ -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()) @@ -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] diff --git a/templates/examples/README.md b/templates/examples/README.md new file mode 100644 index 0000000..2f22765 --- /dev/null +++ b/templates/examples/README.md @@ -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`. diff --git a/templates/examples/browser-playwright.json b/templates/examples/browser-playwright.json new file mode 100644 index 0000000..1769da8 --- /dev/null +++ b/templates/examples/browser-playwright.json @@ -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} +} diff --git a/templates/examples/mcp-server.json b/templates/examples/mcp-server.json new file mode 100644 index 0000000..eeba39f --- /dev/null +++ b/templates/examples/mcp-server.json @@ -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} +} diff --git a/templates/examples/python-data.json b/templates/examples/python-data.json new file mode 100644 index 0000000..c64cc76 --- /dev/null +++ b/templates/examples/python-data.json @@ -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} +} diff --git a/templates/examples/web-app.json b/templates/examples/web-app.json new file mode 100644 index 0000000..f0105ec --- /dev/null +++ b/templates/examples/web-app.json @@ -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} +}