From f8039568bc81061cba38f0161acb2be62cd7ed99 Mon Sep 17 00:00:00 2001 From: Dhruv Jain Date: Mon, 30 Nov 2026 20:47:20 +0530 Subject: [PATCH 1/2] feat: add generic example templates for browser, web apps, MCP, and Python --- crates/spawn-api/src/model.rs | 19 +++++++++---- templates/examples/README.md | 31 ++++++++++++++++++++++ templates/examples/browser-playwright.json | 14 ++++++++++ templates/examples/mcp-server.json | 19 +++++++++++++ templates/examples/python-data.json | 15 +++++++++++ templates/examples/web-app.json | 14 ++++++++++ 6 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 templates/examples/README.md create mode 100644 templates/examples/browser-playwright.json create mode 100644 templates/examples/mcp-server.json create mode 100644 templates/examples/python-data.json create mode 100644 templates/examples/web-app.json 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..f5b1cea --- /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:22-bookworm-slim` | 2 vCPU, 2048 MiB, 20 GiB | Headless Chromium + Playwright on Node.js 22 (non-root safe) | +| `web-app.json` | `web-app` | `node:22-bookworm-slim` | 2 vCPU, 2048 MiB, 20 GiB | Node.js 22 LTS + pnpm runtime for Next.js, Vite, or Express services | +| `mcp-server.json` | `mcp-server` | `node:22-bookworm-slim` | 2 vCPU, 1024 MiB, 10 GiB | Node.js 22 LTS (`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..ce4f1ed --- /dev/null +++ b/templates/examples/browser-playwright.json @@ -0,0 +1,14 @@ +{ + "name": "browser-playwright", + "base": "node:22-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..73d101a --- /dev/null +++ b/templates/examples/mcp-server.json @@ -0,0 +1,19 @@ +{ + "name": "mcp-server", + "base": "node:22-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..a171d74 --- /dev/null +++ b/templates/examples/web-app.json @@ -0,0 +1,14 @@ +{ + "name": "web-app", + "base": "node:22-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} +} From 50b36f680eed8c41c748693e4e9294f7c63e0f4e Mon Sep 17 00:00:00 2001 From: Dhruv Jain Date: Mon, 30 Nov 2026 20:51:43 +0530 Subject: [PATCH 2/2] chore: use node:26-bookworm-slim in example templates --- templates/examples/README.md | 6 +++--- templates/examples/browser-playwright.json | 2 +- templates/examples/mcp-server.json | 2 +- templates/examples/web-app.json | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/templates/examples/README.md b/templates/examples/README.md index f5b1cea..2f22765 100644 --- a/templates/examples/README.md +++ b/templates/examples/README.md @@ -6,9 +6,9 @@ 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:22-bookworm-slim` | 2 vCPU, 2048 MiB, 20 GiB | Headless Chromium + Playwright on Node.js 22 (non-root safe) | -| `web-app.json` | `web-app` | `node:22-bookworm-slim` | 2 vCPU, 2048 MiB, 20 GiB | Node.js 22 LTS + pnpm runtime for Next.js, Vite, or Express services | -| `mcp-server.json` | `mcp-server` | `node:22-bookworm-slim` | 2 vCPU, 1024 MiB, 10 GiB | Node.js 22 LTS (`tsx`) + Python 3 (`mcp`, `uvicorn`) for Streamable HTTP MCP servers | +| `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 diff --git a/templates/examples/browser-playwright.json b/templates/examples/browser-playwright.json index ce4f1ed..1769da8 100644 --- a/templates/examples/browser-playwright.json +++ b/templates/examples/browser-playwright.json @@ -1,6 +1,6 @@ { "name": "browser-playwright", - "base": "node:22-bookworm-slim", + "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/*" diff --git a/templates/examples/mcp-server.json b/templates/examples/mcp-server.json index 73d101a..eeba39f 100644 --- a/templates/examples/mcp-server.json +++ b/templates/examples/mcp-server.json @@ -1,6 +1,6 @@ { "name": "mcp-server", - "base": "node:22-bookworm-slim", + "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", diff --git a/templates/examples/web-app.json b/templates/examples/web-app.json index a171d74..f0105ec 100644 --- a/templates/examples/web-app.json +++ b/templates/examples/web-app.json @@ -1,6 +1,6 @@ { "name": "web-app", - "base": "node:22-bookworm-slim", + "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"