[PR #328] [MERGED] Horizon mods runtime: sandboxed WebAssembly components with wasmtime #2499

Closed
opened 2026-11-02 15:56:42 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/328
Author: @ludovic111
Created: 10/15/2026
Status: ✅ Merged
Merged: 10/15/2026
Merged by: @ludovic111

Base: main ← Head: feat/mod-runtime


📝 Commits (2)

  • 670e055 Horizon mod SDK: the horizon:mods WIT contract, a Rust SDK and an example mod
  • b3906d8 Horizon mods runtime: load sandboxed WebAssembly components with wasmtime

📊 Changes

16 files changed (+2473 additions, -28 deletions)

View changed files

📝 .github/workflows/ci.yml (+1 -1)
📝 Cargo.lock (+973 -26)
📝 Cargo.toml (+1 -1)
➕ crates/horizon-mod-sdk/Cargo.toml (+13 -0)
➕ crates/horizon-mod-sdk/examples/coords-hud/Cargo.toml (+16 -0)
➕ crates/horizon-mod-sdk/examples/coords-hud/horizon-mod.toml (+8 -0)
➕ crates/horizon-mod-sdk/examples/coords-hud/src/lib.rs (+124 -0)
➕ crates/horizon-mod-sdk/src/lib.rs (+141 -0)
➕ crates/horizon-mod-sdk/wit/horizon.wit (+97 -0)
➕ crates/horizon-mods/Cargo.toml (+29 -0)
➕ crates/horizon-mods/src/lib.rs (+14 -0)
➕ crates/horizon-mods/src/manifest.rs (+255 -0)
➕ crates/horizon-mods/src/runtime.rs (+498 -0)
➕ crates/horizon-mods/tests/guest/Cargo.toml (+16 -0)
➕ crates/horizon-mods/tests/guest/src/lib.rs (+44 -0)
➕ crates/horizon-mods/tests/sandbox.rs (+243 -0)

📄 Description

What

Part 2 of the mod foundation (design: #326; stacked on #327).
crates/horizon-mods: loads .hmod files (zip of horizon-mod.toml + mod.wasm) or mod folders and runs them with wasmtime 36 LTS (component model; only runtime, cranelift, component-model, std features; no WASI).

  • Manifest: id, name, version, api 0.1, side, capabilities; unknown keys refused. The component's real imports are checked against the declared capabilities.
  • Sandbox: 64 MiB memory, fuel per call (init 2e9, tick 5e7, frame 1e7, command/chat 1e8), host-side clipping of chat and HUD output. A trap, overrun or OOM stops that mod alone and reports why.
  • Hooks only for mods that asked; vanilla command names refused; hot reload by file time (reload_changed).
  • Mods::default() is the no-mod state: no engine, every hook one check.
  • CI: the verify job installs wasm32-unknown-unknown (the sandbox tests build the example and a misbehaving test guest).

Measured (M4 Pro, release, cargo test -p horizon-mods --release --test sandbox -- --ignored --nocapture)

per call
tick, no mods 1.2 ns
empty tick hook 85.5 ns
empty frame hook 87.5 ns
coords-hud tick 2.3 µs
load coords-hud 49.7 ms (once)

How tested

tests/sandbox.rs: coords-hud draws and answers; off mods cost nothing; undeclared capability refused; vanilla commands win; /spin (endless loop), /panic, /grow (1 GiB) each stop only the guest while coords-hud keeps running; hot reload restarts a rebuilt mod.

cargo fmt --all -- --check                                  ok
cargo clippy --workspace --all-targets -- -D warnings       ok
cargo test -p horizon-mods -p horizon-mod-sdk -p coords-hud -p cargo-horizon-mod   ok (sandbox: 6 passed)
cargo test -p horizon-client                                ok (655 + 41 + 15 + ... passed)

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/328 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/15/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/mod-runtime` --- ### 📝 Commits (2) - [`670e055`](https://github.com/horizon-rust/horizon/commit/670e055f4a0dcf7485eeaac313d3c6157c9b2c65) Horizon mod SDK: the horizon:mods WIT contract, a Rust SDK and an example mod - [`b3906d8`](https://github.com/horizon-rust/horizon/commit/b3906d803d9e082f89b6cebc1f2b7eb4389f0e84) Horizon mods runtime: load sandboxed WebAssembly components with wasmtime ### 📊 Changes **16 files changed** (+2473 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/ci.yml` (+1 -1) 📝 `Cargo.lock` (+973 -26) 📝 `Cargo.toml` (+1 -1) ➕ `crates/horizon-mod-sdk/Cargo.toml` (+13 -0) ➕ `crates/horizon-mod-sdk/examples/coords-hud/Cargo.toml` (+16 -0) ➕ `crates/horizon-mod-sdk/examples/coords-hud/horizon-mod.toml` (+8 -0) ➕ `crates/horizon-mod-sdk/examples/coords-hud/src/lib.rs` (+124 -0) ➕ `crates/horizon-mod-sdk/src/lib.rs` (+141 -0) ➕ `crates/horizon-mod-sdk/wit/horizon.wit` (+97 -0) ➕ `crates/horizon-mods/Cargo.toml` (+29 -0) ➕ `crates/horizon-mods/src/lib.rs` (+14 -0) ➕ `crates/horizon-mods/src/manifest.rs` (+255 -0) ➕ `crates/horizon-mods/src/runtime.rs` (+498 -0) ➕ `crates/horizon-mods/tests/guest/Cargo.toml` (+16 -0) ➕ `crates/horizon-mods/tests/guest/src/lib.rs` (+44 -0) ➕ `crates/horizon-mods/tests/sandbox.rs` (+243 -0) </details> ### 📄 Description ## What Part 2 of the mod foundation (design: #326; stacked on #327). `crates/horizon-mods`: loads `.hmod` files (zip of `horizon-mod.toml` + `mod.wasm`) or mod folders and runs them with wasmtime 36 LTS (component model; only runtime, cranelift, component-model, std features; no WASI). - Manifest: id, name, version, api `0.1`, side, capabilities; unknown keys refused. The component's real imports are checked against the declared capabilities. - Sandbox: 64 MiB memory, fuel per call (init 2e9, tick 5e7, frame 1e7, command/chat 1e8), host-side clipping of chat and HUD output. A trap, overrun or OOM stops that mod alone and reports why. - Hooks only for mods that asked; vanilla command names refused; hot reload by file time (`reload_changed`). - `Mods::default()` is the no-mod state: no engine, every hook one check. - CI: the verify job installs `wasm32-unknown-unknown` (the sandbox tests build the example and a misbehaving test guest). ## Measured (M4 Pro, release, `cargo test -p horizon-mods --release --test sandbox -- --ignored --nocapture`) | | per call | |---|---| | tick, no mods | 1.2 ns | | empty tick hook | 85.5 ns | | empty frame hook | 87.5 ns | | coords-hud tick | 2.3 µs | | load coords-hud | 49.7 ms (once) | ## How tested `tests/sandbox.rs`: coords-hud draws and answers; off mods cost nothing; undeclared capability refused; vanilla commands win; `/spin` (endless loop), `/panic`, `/grow` (1 GiB) each stop only the guest while coords-hud keeps running; hot reload restarts a rebuilt mod. ``` cargo fmt --all -- --check ok cargo clippy --workspace --all-targets -- -D warnings ok cargo test -p horizon-mods -p horizon-mod-sdk -p coords-hud -p cargo-horizon-mod ok (sandbox: 6 passed) cargo test -p horizon-client ok (655 + 41 + 15 + ... passed) ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:56:42 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#2499
No description provided.