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
4 changes: 2 additions & 2 deletions scripts/update-template-refs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#
# scripts/update-template-refs.sh <version> [owner/repo]
# scripts/update-template-refs.sh v0.1.0
# scripts/update-template-refs.sh v0.1.0 myorg/spin-sandboxes
# 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.
set -euo pipefail

VERSION="${1:?usage: $0 <version> [owner/repo]}"
REPO="${2:-fermyon/spin-sandboxes}"
REPO="${2:-spinframework/spin-code-sandbox}"
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

sha256() {
Expand Down
16 changes: 9 additions & 7 deletions templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ npm" capability is isolated from the "run untrusted code" capability.
spin templates install --dir . --upgrade

# or straight from git
spin templates install --git https://github.com/fermyon/spin-sandboxes --upgrade
spin templates install --git https://github.com/spinframework/spin-code-sandbox --upgrade
```

## Use
Expand Down Expand Up @@ -82,17 +82,19 @@ await py.run(code, { lang: "python" }); // application-owned policy, see sdk/REA
2. Point the templates at the new release (fills in real `sha256` digests):

```bash
scripts/update-template-refs.sh vX.Y.Z # uses fermyon/spin-sandboxes
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
```

## Placeholders to set before first release
## Current release pin

The templates ship with placeholder digests (`sha256:0000…0000`) and point at a `v0.1.0`
release of `fermyon/spin-sandboxes`. `update-template-refs.sh` fills in the real
digests after the first release; until then, `spin up` on a generated app fails digest
verification. Forks pass their own `owner/repo` to the script.
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.
Forks pass their own `owner/repo` to the script.

The prebuilt `wasm32-wasi` Python packages are committed in `py-sandbox/wasi-deps`, so
the CI and release workflows need no extra repo, submodule, or secret.
Expand Down
4 changes: 2 additions & 2 deletions templates/sandbox-app/content/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ const py = new Interpreter({ baseUrl: "http://py-sandbox.spin.internal" });
await py.run("print(6 * 7)", { lang: "python" });
```

See [examples/ai-code-executor](https://github.com/fermyon/spin-sandboxes/tree/main/examples/ai-code-executor) for a complete caller. Set `allowedHosts`, `kvEnabled`, and `identity` from application code, never from model output.
See [examples/ai-code-executor](https://github.com/spinframework/spin-code-sandbox/tree/main/examples/ai-code-executor) for a complete caller. Set `allowedHosts`, `kvEnabled`, and `identity` from application code, never from model output.

## Security model

The trust boundary is the Wasm component (no filesystem; egress gated by Spin). Per-sandbox KV keys are namespaced unambiguously, and KV is off unless the caller enables it. Outbound HTTP is default-deny and refuses loopback, link-local, private, and `.internal` targets even if allow-listed. There is no in-component CPU/wall-clock timeout or memory limit, so enforce a request deadline and memory cap at the host/deployment layer.

Each component's `allowed_outbound_hosts` in `spin.toml` starts empty, so user code cannot make outbound requests. Add the hosts it may reach there (for example `["https://api.example.com"]`); a request's `allowedHosts` can then only narrow that list.

To modify or rebuild the components, see [spin-sandboxes](https://github.com/fermyon/spin-sandboxes).
To modify or rebuild the components, see [spin-code-sandbox](https://github.com/spinframework/spin-code-sandbox).
6 changes: 3 additions & 3 deletions templates/sandbox-app/content/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "0.1.0"
authors = ["{{authors}}"]
description = "{{project-description}}"

# Both components are prebuilt and pulled from the spin-sandboxes GitHub releases.
# Both components are prebuilt and pulled from the spin-code-sandbox GitHub releases.
# To move to a newer release, update each source URL and digest.

# Both components are PRIVATE (no public route): they run untrusted code and are reachable
Expand All @@ -25,7 +25,7 @@ route = { private = true }
component = "ts-sandbox"

[component.ts-sandbox]
source = { url = "https://github.com/fermyon/spin-sandboxes/releases/download/v0.1.0/ts-sandbox.wasm", digest = "sha256:0000000000000000000000000000000000000000000000000000000000000000" }
source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/canary/ts-sandbox.wasm", digest = "sha256:5c815217be184d01ad9b1697273ae41dba22c8d1bb6fd47d831a2ebaf04fe30b" }
# 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
Expand All @@ -43,7 +43,7 @@ route = { private = true }
component = "py-sandbox"

[component.py-sandbox]
source = { url = "https://github.com/fermyon/spin-sandboxes/releases/download/v0.1.0/py-sandbox.wasm", digest = "sha256:0000000000000000000000000000000000000000000000000000000000000000" }
source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/canary/py-sandbox.wasm", digest = "sha256:9ab0826b16a066106caf0ef36823a901576eab2f0beb484c8e325deca79c4ad2" }
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
Expand Down
4 changes: 2 additions & 2 deletions templates/sandbox-py/content/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ route = { private = true }
component = "{{project-name | kebab_case}}"

[component.{{project-name | kebab_case}}]
# Prebuilt component from the spin-sandboxes GitHub releases. To move to a
# 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/fermyon/spin-sandboxes/releases/download/v0.1.0/py-sandbox.wasm", digest = "sha256:0000000000000000000000000000000000000000000000000000000000000000" }
source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/canary/py-sandbox.wasm", digest = "sha256:9ab0826b16a066106caf0ef36823a901576eab2f0beb484c8e325deca79c4ad2" }
# 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
Expand Down
2 changes: 1 addition & 1 deletion templates/sandbox-py/metadata/snippets/component.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ route = { private = true }
component = "{{project-name | kebab_case}}"

[component.{{project-name | kebab_case}}]
source = { url = "https://github.com/fermyon/spin-sandboxes/releases/download/v0.1.0/py-sandbox.wasm", digest = "sha256:0000000000000000000000000000000000000000000000000000000000000000" }
source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/canary/py-sandbox.wasm", digest = "sha256:9ab0826b16a066106caf0ef36823a901576eab2f0beb484c8e325deca79c4ad2" }
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
Expand Down
6 changes: 3 additions & 3 deletions templates/sandbox-ts/content/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ route = { private = true }
component = "{{project-name | kebab_case}}"

[component.{{project-name | kebab_case}}]
# Prebuilt components from the spin-sandboxes GitHub releases. To move to a
# 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/fermyon/spin-sandboxes/releases/download/v0.1.0/ts-sandbox.wasm", digest = "sha256:0000000000000000000000000000000000000000000000000000000000000000" }
source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/canary/ts-sandbox.wasm", digest = "sha256:5c815217be184d01ad9b1697273ae41dba22c8d1bb6fd47d831a2ebaf04fe30b" }
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
Expand All @@ -48,7 +48,7 @@ route = { private = true }
component = "{{project-name | kebab_case}}-bundler"

[component.{{project-name | kebab_case}}-bundler]
source = { url = "https://github.com/fermyon/spin-sandboxes/releases/download/v0.1.0/bundler.wasm", digest = "sha256:0000000000000000000000000000000000000000000000000000000000000000" }
source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/canary/bundler.wasm", digest = "sha256:d9f9bfde7a3d24033937cb2af0fe346e0a8a1c47ccdd09f4bfd316ff49480033" }
# 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]
Expand Down
4 changes: 2 additions & 2 deletions templates/sandbox-ts/metadata/snippets/component.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ route = { private = true }
component = "{{project-name | kebab_case}}"

[component.{{project-name | kebab_case}}]
source = { url = "https://github.com/fermyon/spin-sandboxes/releases/download/v0.1.0/ts-sandbox.wasm", digest = "sha256:0000000000000000000000000000000000000000000000000000000000000000" }
source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/canary/ts-sandbox.wasm", digest = "sha256:5c815217be184d01ad9b1697273ae41dba22c8d1bb6fd47d831a2ebaf04fe30b" }
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
Expand All @@ -39,5 +39,5 @@ route = { private = true }
component = "{{project-name | kebab_case}}-bundler"

[component.{{project-name | kebab_case}}-bundler]
source = { url = "https://github.com/fermyon/spin-sandboxes/releases/download/v0.1.0/bundler.wasm", digest = "sha256:0000000000000000000000000000000000000000000000000000000000000000" }
source = { url = "https://github.com/spinframework/spin-code-sandbox/releases/download/canary/bundler.wasm", digest = "sha256:d9f9bfde7a3d24033937cb2af0fe346e0a8a1c47ccdd09f4bfd316ff49480033" }
allowed_outbound_hosts = ["https://esm.sh"]
Loading