diff --git a/examples/ai-code-executor/AGENTS.md b/examples/ai-code-executor/AGENTS.md index 78354f2..07ec2f7 100644 --- a/examples/ai-code-executor/AGENTS.md +++ b/examples/ai-code-executor/AGENTS.md @@ -10,14 +10,14 @@ Five components; only `ui` and `api` have public routes. - **`api/`** (public `/api/...`): a Hono component (TypeScript to Wasm via esbuild + `j2w`). It runs the agent loop in [`api/src/index.ts`](api/src/index.ts): one tool (`run_in_wasm_interpreter`), the system prompt, and the streaming NDJSON protocol. It - depends on the sandbox client [`@spinframework/spin-code-sandbox`](../../sdk) (a local `file:` - dependency in [`api/package.json`](api/package.json)) and holds one `Interpreter` per + depends on the sandbox client [`@spinframework/spin-code-sandbox`](../../sdk) (the published npm + package, a dependency in [`api/package.json`](api/package.json)) and holds one `Interpreter` per language, each pointed at a private interpreter component's `spin.internal` URL. - **`ui/`** (public `/...`): a Nuxt SPA served by the Spin static fileserver. Adapted from the upstream example and trimmed to the interpreter-only surface (a filesystem-assuming prompt was swapped for an interpreter-friendly one). - **`ts-sandbox` / `py-sandbox`** (private, `route = { private = true }`): this repo's - interpreter components, built in place from `../../packages/typescript/sandbox` and `../../py-sandbox`. + interpreter components, pulled prebuilt from the `v0.1.0` GitHub release (URL + digest in `spin.toml`). They have no public route and are reachable only from `api` via service chaining (`ts-sandbox.spin.internal` / `py-sandbox.spin.internal`), which the API lists in its `allowed_outbound_hosts`. @@ -44,7 +44,7 @@ separately. ```bash export SPIN_VARIABLE_MODEL_BASE_URL= SPIN_VARIABLE_MODEL_API_KEY= -spin up --build # Anthropic Messages API; builds all 5 components + serves +spin up --build # Anthropic Messages API; builds the api and ui, pulls the released sandboxes spin up --profile openai --build # OpenAI Chat Completions API ``` diff --git a/examples/ai-code-executor/README.md b/examples/ai-code-executor/README.md index 49bffa9..6adda56 100644 --- a/examples/ai-code-executor/README.md +++ b/examples/ai-code-executor/README.md @@ -17,8 +17,8 @@ The two interpreters (`ts-sandbox`, `py-sandbox`) are private components of this (`route = { private = true }`), so they have no public route and are reachable only from the `api` component via local service chaining (`.spin.internal`). A private `bundler` component (experimental) packages any extra npm dependencies the model requests. The -API depends on the sandbox client from this repo ([`@spinframework/spin-code-sandbox`](../../sdk), -a local `file:` dependency) and holds one `Interpreter` per language, each pointed at +API depends on the sandbox client ([`@spinframework/spin-code-sandbox`](../../sdk), +the published npm package) and holds one `Interpreter` per language, each pointed at its component's internal URL. ## How it works: the CodeAct pattern @@ -138,9 +138,10 @@ at an external sandbox instead. Everything is one app, with no separate interpreter to start. -1. Build: `spin build` (add `--profile openai` for the OpenAI build) builds all five components: the API (esbuild + `j2w`), the UI - (`nuxt generate`), the two private interpreters, and the private bundler (this - repo's components, built in place from `../../`). +1. Build: `spin build` (add `--profile openai` for the OpenAI build) builds the API (esbuild + `j2w`) + and the UI (`nuxt generate`). The two private interpreters and the private bundler are + prebuilt components from this repo's `v0.1.0` GitHub release, which Spin downloads and + verifies by digest. 2. Run (the model server and key come from the environment): ```bash export SPIN_VARIABLE_MODEL_BASE_URL= SPIN_VARIABLE_MODEL_API_KEY= @@ -200,7 +201,7 @@ api/ Hono component: the LLM tool-use loop + the interpreter tool src/llm/ provider interface + Anthropic and OpenAI implementations (one bundled per build) ui/ Nuxt SPA chat (near-verbatim from upstream; one filesystem prompt swapped) pages/index.vue the chat UI -../../packages/typescript/sandbox private JS/TS interpreter, built in place, reached via ts-sandbox.spin.internal -../../py-sandbox private Python interpreter, built in place, reached via py-sandbox.spin.internal -../../packages/typescript/bundler experimental private npm bundler, built in place, reached via bundler.spin.internal +ts-sandbox.wasm private JS/TS interpreter (v0.1.0 release), reached via ts-sandbox.spin.internal +py-sandbox.wasm private Python interpreter (v0.1.0 release), reached via py-sandbox.spin.internal +bundler.wasm experimental private npm bundler (v0.1.0 release), reached via bundler.spin.internal ``` diff --git a/examples/ai-code-executor/api/build.mjs b/examples/ai-code-executor/api/build.mjs index ec98f33..743326e 100644 --- a/examples/ai-code-executor/api/build.mjs +++ b/examples/ai-code-executor/api/build.mjs @@ -50,7 +50,5 @@ await build({ '.tsx': 'tsx', }, resolveExtensions: ['.ts', '.tsx', '.js'], - // The SDK is linked from ../../../sdk; resolve its peer dependencies (zod) from this app. - nodePaths: [path.resolve('node_modules')], sourceRoot: path.resolve(process.cwd(), 'src'), }); diff --git a/examples/ai-code-executor/api/package-lock.json b/examples/ai-code-executor/api/package-lock.json index e9ab0b5..249a1bf 100644 --- a/examples/ai-code-executor/api/package-lock.json +++ b/examples/ai-code-executor/api/package-lock.json @@ -10,7 +10,7 @@ "license": "Apache-2.0 WITH LLVM-exception", "dependencies": { "@anthropic-ai/sdk": "^0.69.0", - "@spinframework/spin-code-sandbox": "file:../../../sdk", + "@spinframework/spin-code-sandbox": "^0.1.0", "@spinframework/spin-variables": "^1.0.1", "@spinframework/wasi-http-proxy": "^2.0.0", "hono": "^4.13.19", @@ -23,23 +23,6 @@ "typescript": "^5.6.0" } }, - "../../../sdk": { - "name": "@spinframework/spin-code-sandbox", - "version": "0.1.0", - "license": "Apache-2.0 WITH LLVM-exception", - "devDependencies": { - "typescript": "^5.6.0", - "zod": "^4.6.7" - }, - "peerDependencies": { - "zod": "^4.0.0" - }, - "peerDependenciesMeta": { - "zod": { - "optional": true - } - } - }, "node_modules/@ampproject/remapping": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", @@ -2541,8 +2524,18 @@ } }, "node_modules/@spinframework/spin-code-sandbox": { - "resolved": "../../../sdk", - "link": true + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@spinframework/spin-code-sandbox/-/spin-code-sandbox-0.1.0.tgz", + "integrity": "sha512-xDeCiPZxG0rRhvXCCapej0esi0N/TYPxN7tNi52xfdeT4EZ/IN+hYLRRildxQlzy9Yk0gtYxrowWWnS2WKFaLA==", + "license": "Apache-2.0 WITH LLVM-exception", + "peerDependencies": { + "zod": "^4.0.0" + }, + "peerDependenciesMeta": { + "zod": { + "optional": true + } + } }, "node_modules/@spinframework/spin-variables": { "version": "1.0.1", diff --git a/examples/ai-code-executor/api/package.json b/examples/ai-code-executor/api/package.json index 4e25f4f..a747da7 100644 --- a/examples/ai-code-executor/api/package.json +++ b/examples/ai-code-executor/api/package.json @@ -19,7 +19,7 @@ }, "dependencies": { "@anthropic-ai/sdk": "^0.69.0", - "@spinframework/spin-code-sandbox": "file:../../../sdk", + "@spinframework/spin-code-sandbox": "^0.1.0", "@spinframework/spin-variables": "^1.0.1", "@spinframework/wasi-http-proxy": "^2.0.0", "hono": "^4.13.19", diff --git a/examples/ai-code-executor/api/tsconfig.json b/examples/ai-code-executor/api/tsconfig.json index 162f95a..5a47ccf 100644 --- a/examples/ai-code-executor/api/tsconfig.json +++ b/examples/ai-code-executor/api/tsconfig.json @@ -17,8 +17,7 @@ "allowImportingTsExtensions": true, "noEmit": true, "paths": { - "#llm-provider": ["./src/llm/anthropic.ts"], - "zod": ["./node_modules/zod"] + "#llm-provider": ["./src/llm/anthropic.ts"] } }, "include": [ diff --git a/examples/ai-code-executor/spin.toml b/examples/ai-code-executor/spin.toml index 7662feb..f79a93e 100644 --- a/examples/ai-code-executor/spin.toml +++ b/examples/ai-code-executor/spin.toml @@ -73,8 +73,7 @@ route = { private = true } component = "ts-sandbox" [component.ts-sandbox] -source = "../../dist/ts-sandbox.wasm" -exclude_files = ["**/node_modules"] +source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/v0.1.0/ts-sandbox.wasm", digest = "sha256:533eaa2d7d5a3318951bebd576e847740d61e89c6299129a3b754aaf04150e89" } key_value_stores = ["default"] # Outbound HTTP is denied until you list hosts here, e.g. ["https://api.example.com"]. Each # request's `allowedHosts` can only narrow this list, and it always refuses private and @@ -82,25 +81,18 @@ key_value_stores = ["default"] allowed_outbound_hosts = [] [component.ts-sandbox.variables] log_level = "{{ log_level }}" -[component.ts-sandbox.build] -command = "bash build-composed.sh" -workdir = "../../packages/typescript/sandbox" [[trigger.http]] route = { private = true } component = "py-sandbox" [component.py-sandbox] -source = "../../dist/py-sandbox.wasm" +source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/v0.1.0/py-sandbox.wasm", digest = "sha256:a2e5be435099a849e04242120524d937ca1411c413e32227f4d6c00f698d3a85" } key_value_stores = ["default"] # Outbound HTTP is denied until you list hosts here, e.g. ["https://api.example.com"]. Each # request's `allowedHosts` can only narrow this list, and it always refuses private and # internal addresses. allowed_outbound_hosts = [] -[component.py-sandbox.build] -command = "bash build-composed.sh" -workdir = "../../py-sandbox" -watch = ["*.py", "requirements.txt"] # EXPERIMENTAL private bundler for JavaScript npm dependencies: the SDK POSTs (source + package.json) # here and runs the returned self-contained bundle. It fetches deps from esm.sh (esm_base_url) @@ -110,11 +102,7 @@ route = { private = true } component = "bundler" [component.bundler] -source = "../../packages/typescript/bundler/dist/bundler.wasm" -exclude_files = ["**/node_modules"] +source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/v0.1.0/bundler.wasm", digest = "sha256:b4430fa74eae6d2db0f32c829ffd53472d093fb5176cb0502c90f002bf7d01d3" } allowed_outbound_hosts = ["{{ esm_base_url }}"] [component.bundler.variables] esm_base_url = "{{ esm_base_url }}" -[component.bundler.build] -command = "npm ci && npm run build" -workdir = "../../packages/typescript/bundler" diff --git a/examples/app-builder/AGENTS.md b/examples/app-builder/AGENTS.md index afbb273..18f6ba6 100644 --- a/examples/app-builder/AGENTS.md +++ b/examples/app-builder/AGENTS.md @@ -19,7 +19,7 @@ Five components; only `ui` and `api` have public routes. of stored apps and a "describe an app" create flow that streams the generation and links to the live URL. - **`ts-sandbox` / `py-sandbox`** (private, `route = { private = true }`): this repo's - interpreter components, built in place from `../../`. They execute the stored handler; + interpreter components, pulled prebuilt from the `v0.1.0` GitHub release. They execute the stored handler; ts-sandbox also holds the code store in its scoped `default` KV. Reachable only from `api` via service chaining. - **`bundler`** (private, experimental): bundles a JS app's npm `dependencies` once at publish time; diff --git a/examples/app-builder/README.md b/examples/app-builder/README.md index 4da575f..20c1ead 100644 --- a/examples/app-builder/README.md +++ b/examples/app-builder/README.md @@ -160,7 +160,7 @@ api/ Hono component: the LLM loop, the code store, and the live-se src/llm/ provider interface + Anthropic and OpenAI implementations (one bundled per build) ui/ Nuxt SPA: build gallery + create flow pages/index.vue the gallery + "describe an app" UI -../../packages/typescript/sandbox private JS/TS interpreter, built in place, reached via ts-sandbox.spin.internal -../../py-sandbox private Python interpreter, built in place, reached via py-sandbox.spin.internal -../../packages/typescript/bundler experimental private npm bundler, built in place, reached via bundler.spin.internal +ts-sandbox.wasm private JS/TS interpreter (v0.1.0 release), reached via ts-sandbox.spin.internal +py-sandbox.wasm private Python interpreter (v0.1.0 release), reached via py-sandbox.spin.internal +bundler.wasm experimental private npm bundler (v0.1.0 release), reached via bundler.spin.internal ``` diff --git a/examples/app-builder/api/package-lock.json b/examples/app-builder/api/package-lock.json index 495b56a..ea23882 100644 --- a/examples/app-builder/api/package-lock.json +++ b/examples/app-builder/api/package-lock.json @@ -10,7 +10,7 @@ "license": "Apache-2.0 WITH LLVM-exception", "dependencies": { "@anthropic-ai/sdk": "^0.69.0", - "@spinframework/spin-code-sandbox": "file:../../../sdk", + "@spinframework/spin-code-sandbox": "^0.1.0", "@spinframework/spin-variables": "^1.0.1", "@spinframework/wasi-http-proxy": "^2.0.0", "hono": "^4.13.19", @@ -22,23 +22,6 @@ "typescript": "^5.6.0" } }, - "../../../sdk": { - "name": "@spinframework/spin-code-sandbox", - "version": "0.1.0", - "license": "Apache-2.0 WITH LLVM-exception", - "devDependencies": { - "typescript": "^5.6.0", - "zod": "^4.6.7" - }, - "peerDependencies": { - "zod": "^4.0.0" - }, - "peerDependenciesMeta": { - "zod": { - "optional": true - } - } - }, "node_modules/@ampproject/remapping": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", @@ -2540,8 +2523,18 @@ } }, "node_modules/@spinframework/spin-code-sandbox": { - "resolved": "../../../sdk", - "link": true + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@spinframework/spin-code-sandbox/-/spin-code-sandbox-0.1.0.tgz", + "integrity": "sha512-xDeCiPZxG0rRhvXCCapej0esi0N/TYPxN7tNi52xfdeT4EZ/IN+hYLRRildxQlzy9Yk0gtYxrowWWnS2WKFaLA==", + "license": "Apache-2.0 WITH LLVM-exception", + "peerDependencies": { + "zod": "^4.0.0" + }, + "peerDependenciesMeta": { + "zod": { + "optional": true + } + } }, "node_modules/@spinframework/spin-variables": { "version": "1.0.1", diff --git a/examples/app-builder/api/package.json b/examples/app-builder/api/package.json index c896799..9dbf071 100644 --- a/examples/app-builder/api/package.json +++ b/examples/app-builder/api/package.json @@ -19,7 +19,7 @@ }, "dependencies": { "@anthropic-ai/sdk": "^0.69.0", - "@spinframework/spin-code-sandbox": "file:../../../sdk", + "@spinframework/spin-code-sandbox": "^0.1.0", "@spinframework/spin-variables": "^1.0.1", "@spinframework/wasi-http-proxy": "^2.0.0", "hono": "^4.13.19", diff --git a/examples/app-builder/spin.toml b/examples/app-builder/spin.toml index 5baf58f..5513350 100644 --- a/examples/app-builder/spin.toml +++ b/examples/app-builder/spin.toml @@ -80,8 +80,7 @@ route = { private = true } component = "ts-sandbox" [component.ts-sandbox] -source = "../../dist/ts-sandbox.wasm" -exclude_files = ["**/node_modules"] +source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/v0.1.0/ts-sandbox.wasm", digest = "sha256:533eaa2d7d5a3318951bebd576e847740d61e89c6299129a3b754aaf04150e89" } key_value_stores = ["default"] # Outbound HTTP is denied until you list hosts here, e.g. ["https://api.example.com"]. Each # request's `allowedHosts` can only narrow this list, and it always refuses private and @@ -89,25 +88,18 @@ key_value_stores = ["default"] allowed_outbound_hosts = [] [component.ts-sandbox.variables] log_level = "{{ log_level }}" -[component.ts-sandbox.build] -command = "bash build-composed.sh" -workdir = "../../packages/typescript/sandbox" [[trigger.http]] route = { private = true } component = "py-sandbox" [component.py-sandbox] -source = "../../dist/py-sandbox.wasm" +source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/v0.1.0/py-sandbox.wasm", digest = "sha256:a2e5be435099a849e04242120524d937ca1411c413e32227f4d6c00f698d3a85" } key_value_stores = ["default"] # Outbound HTTP is denied until you list hosts here, e.g. ["https://api.example.com"]. Each # request's `allowedHosts` can only narrow this list, and it always refuses private and # internal addresses. allowed_outbound_hosts = [] -[component.py-sandbox.build] -command = "bash build-composed.sh" -workdir = "../../py-sandbox" -watch = ["*.py", "requirements.txt"] # EXPERIMENTAL private bundler for JavaScript npm dependencies. Apps with deps are bundled once # at publish (KvCodeStore stores the self-contained blob) and served from it. It fetches deps @@ -118,11 +110,7 @@ route = { private = true } component = "bundler" [component.bundler] -source = "../../packages/typescript/bundler/dist/bundler.wasm" -exclude_files = ["**/node_modules"] +source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/v0.1.0/bundler.wasm", digest = "sha256:b4430fa74eae6d2db0f32c829ffd53472d093fb5176cb0502c90f002bf7d01d3" } allowed_outbound_hosts = ["{{ esm_base_url }}"] [component.bundler.variables] esm_base_url = "{{ esm_base_url }}" -[component.bundler.build] -command = "npm ci && npm run build" -workdir = "../../packages/typescript/bundler" diff --git a/examples/sdk-component/README.md b/examples/sdk-component/README.md index 7b9a03c..c3e8f3e 100644 --- a/examples/sdk-component/README.md +++ b/examples/sdk-component/README.md @@ -10,13 +10,8 @@ durable storage. ## Run -Build the hardened, composed sandbox artifacts from the repository root first: - -```bash -spin build -``` - -Then start this app: +The sandbox components come prebuilt from this repo's `v0.1.0` GitHub release (Spin downloads +them and verifies their digests), so only the `api` component is built locally: ```bash cd examples/sdk-component diff --git a/examples/sdk-component/api/package-lock.json b/examples/sdk-component/api/package-lock.json index 0b1d7a4..34ff2b9 100644 --- a/examples/sdk-component/api/package-lock.json +++ b/examples/sdk-component/api/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.0", "license": "Apache-2.0 WITH LLVM-exception", "dependencies": { - "@spinframework/spin-code-sandbox": "file:../../../sdk", + "@spinframework/spin-code-sandbox": "^0.1.0", "@spinframework/wasi-http-proxy": "^2.0.0", "hono": "^4.13.19" }, @@ -18,23 +18,6 @@ "mkdirp": "^3.0.1" } }, - "../../../sdk": { - "name": "@spinframework/spin-code-sandbox", - "version": "0.1.0", - "license": "Apache-2.0 WITH LLVM-exception", - "devDependencies": { - "typescript": "^5.6.0", - "zod": "^4.6.7" - }, - "peerDependencies": { - "zod": "^4.0.0" - }, - "peerDependenciesMeta": { - "zod": { - "optional": true - } - } - }, "node_modules/@ampproject/remapping": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", @@ -2490,8 +2473,18 @@ } }, "node_modules/@spinframework/spin-code-sandbox": { - "resolved": "../../../sdk", - "link": true + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@spinframework/spin-code-sandbox/-/spin-code-sandbox-0.1.0.tgz", + "integrity": "sha512-xDeCiPZxG0rRhvXCCapej0esi0N/TYPxN7tNi52xfdeT4EZ/IN+hYLRRildxQlzy9Yk0gtYxrowWWnS2WKFaLA==", + "license": "Apache-2.0 WITH LLVM-exception", + "peerDependencies": { + "zod": "^4.0.0" + }, + "peerDependenciesMeta": { + "zod": { + "optional": true + } + } }, "node_modules/@spinframework/wasi-http-proxy": { "version": "2.0.0", diff --git a/examples/sdk-component/api/package.json b/examples/sdk-component/api/package.json index 2407745..d49bd98 100644 --- a/examples/sdk-component/api/package.json +++ b/examples/sdk-component/api/package.json @@ -8,7 +8,7 @@ "build": "node build.mjs && mkdirp dist && j2w -i build/bundle.js --initLocation http://api.localhost -o dist/api.wasm" }, "dependencies": { - "@spinframework/spin-code-sandbox": "file:../../../sdk", + "@spinframework/spin-code-sandbox": "^0.1.0", "@spinframework/wasi-http-proxy": "^2.0.0", "hono": "^4.13.19" }, diff --git a/examples/sdk-component/spin.toml b/examples/sdk-component/spin.toml index 2c8d785..e834419 100644 --- a/examples/sdk-component/spin.toml +++ b/examples/sdk-component/spin.toml @@ -24,7 +24,7 @@ route = { private = true } component = "ts-sandbox" [component.ts-sandbox] -source = "../../dist/ts-sandbox.wasm" +source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/v0.1.0/ts-sandbox.wasm", digest = "sha256:533eaa2d7d5a3318951bebd576e847740d61e89c6299129a3b754aaf04150e89" } key_value_stores = ["default"] # This example never passes allowedHosts, so its sandboxes need no outbound access. Widen this # only together with the per-request allow-list, the guard's narrower check. @@ -35,7 +35,7 @@ route = { private = true } component = "py-sandbox" [component.py-sandbox] -source = "../../dist/py-sandbox.wasm" +source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/v0.1.0/py-sandbox.wasm", digest = "sha256:a2e5be435099a849e04242120524d937ca1411c413e32227f4d6c00f698d3a85" } key_value_stores = ["default"] # This example never passes allowedHosts, so its sandboxes need no outbound access. Widen this # only together with the per-request allow-list, the guard's narrower check. diff --git a/scripts/update-template-refs.sh b/scripts/update-template-refs.sh index a8b6bd6..e6c445a 100755 --- a/scripts/update-template-refs.sh +++ b/scripts/update-template-refs.sh @@ -1,13 +1,14 @@ #!/usr/bin/env bash -# Point the Spin templates at a published release: rewrite the component `source` URL and -# its sha256 digest in every templates/sandbox-*/**/{spin.toml,component.txt}. +# Point the Spin templates and examples at a published release: rewrite the component +# `source` URL and its sha256 digest in every templates/**/{spin.toml,component.txt} and +# examples/*/spin.toml. # # scripts/update-template-refs.sh [owner/repo] # scripts/update-template-refs.sh v0.1.0 # scripts/update-template-refs.sh v0.1.0 myorg/spin-code-sandbox # # Downloads each released *.wasm, computes its digest, and updates the templates in place. -# Review with `git diff templates/` afterwards. +# Review with `git diff templates/ examples/` afterwards. set -euo pipefail VERSION="${1:?usage: $0 [owner/repo]}" @@ -29,21 +30,23 @@ for comp in ts-sandbox py-sandbox bundler; do echo " $digest" # Rewrite `... url = "", digest = "sha256:<64hex>" ...`. - # perl's s/// exits 0 whether or not it matched, so track that at least one file actually - # changed and fail loudly otherwise (e.g. if the template's source-line format drifts). - rewrote=0 + # perl's s/// exits 0 whether or not it matched, so count the files that end up pinned to + # this url and digest, and fail if none do (e.g. the source-line format drifted). Counting + # results rather than changes keeps a re-run for the same release from failing. + pinned=0 while IFS= read -r f; do - before="$(cat "$f")" comp="$comp" url="$url" digest="$digest" perl -i -pe ' my ($c, $u, $d) = ($ENV{comp}, $ENV{url}, $ENV{digest}); s{https://github\.com/[^"]*/\Q$c\E\.wasm", digest = "sha256:[0-9a-f]{64}"}{$u", digest = "$d"}g; ' "$f" - [ "$(cat "$f")" != "$before" ] && rewrote=$((rewrote + 1)) - done < <(grep -rl "/$comp.wasm" "$ROOT/templates") - if [ "$rewrote" -eq 0 ]; then - echo " ERROR: no template rewritten for $comp; the source/digest line format may have changed" >&2 + grep -qF "$url\", digest = \"$digest\"" "$f" && pinned=$((pinned + 1)) + done < <(grep -rl --include=spin.toml --include=component.txt --exclude-dir=node_modules \ + "/$comp.wasm" "$ROOT/templates" "$ROOT/examples") + echo " pinned in $pinned file(s)" + if [ "$pinned" -eq 0 ]; then + echo " ERROR: no template or example pinned for $comp; the source/digest line format may have changed" >&2 exit 1 fi done -echo ">> done, review: git diff templates/" +echo ">> done, review: git diff templates/ examples/" diff --git a/templates/README.md b/templates/README.md index 6da35dd..fd1dec1 100644 --- a/templates/README.md +++ b/templates/README.md @@ -79,21 +79,19 @@ await py.run(code, { lang: "python" }); // application-owned policy, see sdk/REA prerelease). The workflow runs the full test workflow, then builds `ts-sandbox.wasm`, `py-sandbox.wasm`, and `bundler.wasm` from the same commit and uploads them, plus a `checksums-*.txt`, to the release. -2. Point the templates at the new release (fills in real `sha256` digests): +2. Point the templates and the examples at the new release (fills in real `sha256` digests): ```bash scripts/update-template-refs.sh vX.Y.Z # uses spinframework/spin-code-sandbox scripts/update-template-refs.sh vX.Y.Z myorg/repo # or specify your fork - git diff templates/ # review, then commit + git diff templates/ examples/ # review, then commit ``` ## Current release pin -Until the first versioned release, the templates point at the rolling `canary` -prerelease of `spinframework/spin-code-sandbox`. Every Release workflow run rebuilds the -`canary` assets, which changes their digests, so `spin up` on a generated app fails -digest verification until you re-run `scripts/update-template-refs.sh canary`. Once a -`vX.Y.Z` tag exists, pin the templates to it instead; versioned assets never change. +The templates and examples are pinned to the `v0.1.0` release of `spinframework/spin-code-sandbox`. +Versioned assets never change, so their digests stay valid. After each new `vX.Y.Z` +release, re-run `scripts/update-template-refs.sh vX.Y.Z` to move the pin. Forks pass their own `owner/repo` to the script. The prebuilt `wasm32-wasi` Python packages are committed in `py-sandbox/wasi-deps`, so diff --git a/templates/sandbox-app/content/spin.toml b/templates/sandbox-app/content/spin.toml index 5908194..a203d04 100644 --- a/templates/sandbox-app/content/spin.toml +++ b/templates/sandbox-app/content/spin.toml @@ -25,7 +25,7 @@ route = { private = true } component = "ts-sandbox" [component.ts-sandbox] -source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/canary/ts-sandbox.wasm", digest = "sha256:5c815217be184d01ad9b1697273ae41dba22c8d1bb6fd47d831a2ebaf04fe30b" } +source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/v0.1.0/ts-sandbox.wasm", digest = "sha256:533eaa2d7d5a3318951bebd576e847740d61e89c6299129a3b754aaf04150e89" } # Single shared KV store; the component scopes keys per sandbox id. key_value_stores = ["default"] # Outbound HTTP is denied until you list hosts here, e.g. ["https://api.example.com"]. Each @@ -43,7 +43,7 @@ route = { private = true } component = "py-sandbox" [component.py-sandbox] -source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/canary/py-sandbox.wasm", digest = "sha256:9ab0826b16a066106caf0ef36823a901576eab2f0beb484c8e325deca79c4ad2" } +source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/v0.1.0/py-sandbox.wasm", digest = "sha256:a2e5be435099a849e04242120524d937ca1411c413e32227f4d6c00f698d3a85" } key_value_stores = ["default"] # Outbound HTTP is denied until you list hosts here, e.g. ["https://api.example.com"]. Each # request's `allowedHosts` can only narrow this list, and it always refuses private and diff --git a/templates/sandbox-py/content/spin.toml b/templates/sandbox-py/content/spin.toml index 932fc87..e339c87 100644 --- a/templates/sandbox-py/content/spin.toml +++ b/templates/sandbox-py/content/spin.toml @@ -23,7 +23,7 @@ component = "{{project-name | kebab_case}}" [component.{{project-name | kebab_case}}] # Prebuilt component from the spin-code-sandbox GitHub releases. To move to a # newer release, update the source URL and digest. -source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/canary/py-sandbox.wasm", digest = "sha256:9ab0826b16a066106caf0ef36823a901576eab2f0beb484c8e325deca79c4ad2" } +source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/v0.1.0/py-sandbox.wasm", digest = "sha256:a2e5be435099a849e04242120524d937ca1411c413e32227f4d6c00f698d3a85" } # The component scopes KV keys per sandboxId. key_value_stores = ["default"] # Outbound HTTP is denied until you list hosts here, e.g. ["https://api.example.com"]. Each diff --git a/templates/sandbox-py/metadata/snippets/component.txt b/templates/sandbox-py/metadata/snippets/component.txt index e9e97e2..9d97a6f 100644 --- a/templates/sandbox-py/metadata/snippets/component.txt +++ b/templates/sandbox-py/metadata/snippets/component.txt @@ -10,7 +10,7 @@ route = { private = true } component = "{{project-name | kebab_case}}" [component.{{project-name | kebab_case}}] -source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/canary/py-sandbox.wasm", digest = "sha256:9ab0826b16a066106caf0ef36823a901576eab2f0beb484c8e325deca79c4ad2" } +source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/v0.1.0/py-sandbox.wasm", digest = "sha256:a2e5be435099a849e04242120524d937ca1411c413e32227f4d6c00f698d3a85" } key_value_stores = ["default"] # Outbound HTTP is denied until you list hosts here, e.g. ["https://api.example.com"]. Each # request's `allowedHosts` can only narrow this list, and guard-io always refuses private and diff --git a/templates/sandbox-ts/content/spin.toml b/templates/sandbox-ts/content/spin.toml index df05fce..6d48c75 100644 --- a/templates/sandbox-ts/content/spin.toml +++ b/templates/sandbox-ts/content/spin.toml @@ -33,7 +33,7 @@ component = "{{project-name | kebab_case}}" [component.{{project-name | kebab_case}}] # Prebuilt components from the spin-code-sandbox GitHub releases. To move to a # newer release, update each source URL and digest. -source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/canary/ts-sandbox.wasm", digest = "sha256:5c815217be184d01ad9b1697273ae41dba22c8d1bb6fd47d831a2ebaf04fe30b" } +source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/v0.1.0/ts-sandbox.wasm", digest = "sha256:533eaa2d7d5a3318951bebd576e847740d61e89c6299129a3b754aaf04150e89" } key_value_stores = ["default"] # Outbound HTTP is denied until you list hosts here, e.g. ["https://api.example.com"]. Each # request's `allowedHosts` can only narrow this list, and guard-io always refuses private and @@ -48,7 +48,7 @@ route = { private = true } component = "{{project-name | kebab_case}}-bundler" [component.{{project-name | kebab_case}}-bundler] -source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/canary/bundler.wasm", digest = "sha256:d9f9bfde7a3d24033937cb2af0fe346e0a8a1c47ccdd09f4bfd316ff49480033" } +source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/v0.1.0/bundler.wasm", digest = "sha256:b4430fa74eae6d2db0f32c829ffd53472d093fb5176cb0502c90f002bf7d01d3" } # The bundler's only egress is the esm.sh server named by esm_base_url (trusted build infra). allowed_outbound_hosts = ["{% raw %}{{ esm_base_url }}{% endraw %}"] [component.{{project-name | kebab_case}}-bundler.variables] diff --git a/templates/sandbox-ts/metadata/snippets/component.txt b/templates/sandbox-ts/metadata/snippets/component.txt index 7f4b879..97a264d 100644 --- a/templates/sandbox-ts/metadata/snippets/component.txt +++ b/templates/sandbox-ts/metadata/snippets/component.txt @@ -21,7 +21,7 @@ route = { private = true } component = "{{project-name | kebab_case}}" [component.{{project-name | kebab_case}}] -source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/canary/ts-sandbox.wasm", digest = "sha256:5c815217be184d01ad9b1697273ae41dba22c8d1bb6fd47d831a2ebaf04fe30b" } +source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/v0.1.0/ts-sandbox.wasm", digest = "sha256:533eaa2d7d5a3318951bebd576e847740d61e89c6299129a3b754aaf04150e89" } key_value_stores = ["default"] # Outbound HTTP is denied until you list hosts here, e.g. ["https://api.example.com"]. Each # request's `allowedHosts` can only narrow this list, and guard-io always refuses private and @@ -39,5 +39,5 @@ route = { private = true } component = "{{project-name | kebab_case}}-bundler" [component.{{project-name | kebab_case}}-bundler] -source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/canary/bundler.wasm", digest = "sha256:d9f9bfde7a3d24033937cb2af0fe346e0a8a1c47ccdd09f4bfd316ff49480033" } +source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/v0.1.0/bundler.wasm", digest = "sha256:b4430fa74eae6d2db0f32c829ffd53472d093fb5176cb0502c90f002bf7d01d3" } allowed_outbound_hosts = ["https://esm.sh"]