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
8 changes: 4 additions & 4 deletions examples/ai-code-executor/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -44,7 +44,7 @@ separately.

```bash
export SPIN_VARIABLE_MODEL_BASE_URL=<model-base-url> SPIN_VARIABLE_MODEL_API_KEY=<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
```

Expand Down
17 changes: 9 additions & 8 deletions examples/ai-code-executor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (`<component>.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
Expand Down Expand Up @@ -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=<model-base-url> SPIN_VARIABLE_MODEL_API_KEY=<api-key>
Expand Down Expand Up @@ -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
```
2 changes: 0 additions & 2 deletions examples/ai-code-executor/api/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
});
33 changes: 13 additions & 20 deletions examples/ai-code-executor/api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/ai-code-executor/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions examples/ai-code-executor/api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
18 changes: 3 additions & 15 deletions examples/ai-code-executor/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,34 +73,26 @@ 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
# internal addresses.
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)
Expand All @@ -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"
2 changes: 1 addition & 1 deletion examples/app-builder/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions examples/app-builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
33 changes: 13 additions & 20 deletions examples/app-builder/api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/app-builder/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 3 additions & 15 deletions examples/app-builder/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,34 +80,26 @@ 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
# internal addresses.
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
Expand All @@ -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"
9 changes: 2 additions & 7 deletions examples/sdk-component/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 13 additions & 20 deletions examples/sdk-component/api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading