Skip to content

Feature-gated Wasm host tools for the CLI#91

Open
cachebag wants to merge 7 commits into
hyperlight-dev:mainfrom
cachebag:main
Open

Feature-gated Wasm host tools for the CLI#91
cachebag wants to merge 7 commits into
hyperlight-dev:mainfrom
cachebag:main

Conversation

@cachebag

@cachebag cachebag commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

This adds --tool name=./handler.wasm support behind a new wasm-host-fns Cargo feature. The CLI now can register WASIp1 modules as custom host tools and route guest __dispatch calls to them through the existing ToolRegistry path.

Each Wasm tool is compiled and linked before the VM boots, then invoked as a fresh WASIp1 command per tool call. The handler gets the normal dispatch envelope on stdin, {"name":"...","args":...}, and writes either a raw JSON result or a {"result": ...} / {"error": "..."} envelope to stdout. WASI filesystem and env access are capability-based and off by default, with explicit --tool-wasi-dir, --tool-wasi-dir-ro, --tool-wasi-env, and --tool-wasi-env-inherit flags. Calls also have fuel and stdout/stderr capture limits.

Closes #84

cachebag added 4 commits June 8, 2026 22:21
Signed-off-by: akrm al-hakimi <alhakimiakrmj@gmail.com>
Signed-off-by: akrm al-hakimi <alhakimiakrmj@gmail.com>
Signed-off-by: akrm al-hakimi <alhakimiakrmj@gmail.com>
Signed-off-by: akrm al-hakimi <alhakimiakrmj@gmail.com>
Copilot AI review requested due to automatic review settings June 9, 2026 02:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for registering and invoking host-side custom tools implemented as WASI Preview1 WebAssembly modules (behind an optional Cargo feature), including CLI flags and documentation updates.

Changes:

  • Introduces a wasm-host-fns feature with optional wasmtime/wasmtime-wasi dependencies and a new Wasm tool runner (WasmTool).
  • Extends the host CLI to register --tool NAME=WASM tools and configure their WASI capabilities/limits (--tool-wasi-*).
  • Updates docs and README to describe the new tool mechanism and its security/limits model.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
host/src/wasm_host_fns.rs New Wasm tool loader/invoker with WASI Preview1 wiring, option parsing, stdout parsing, and tests.
host/src/main.rs Adds feature-gated CLI flags for Wasm tools and registers tools into SandboxBuilder.
host/Cargo.toml Adds wasm-host-fns feature and optional wasmtime / wasmtime-wasi deps.
docs/host_functions.md Documents --tool and --tool-wasi-* behavior, protocol, and limits.
README.md Updates dispatch surface description and adds usage docs for Wasm host tools.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread host/src/wasm_host_fns.rs Outdated
Comment thread host/src/wasm_host_fns.rs
Comment thread host/src/wasm_host_fns.rs
@cachebag cachebag requested a review from Copilot June 9, 2026 02:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 6 changed files in this pull request and generated 5 comments.

Comment thread host/src/wasm_host_fns.rs
Comment thread host/Cargo.toml
Comment thread host/Cargo.toml
Comment thread host/src/wasm_host_fns.rs
Comment thread host/src/wasm_host_fns.rs
Signed-off-by: akrm al-hakimi <alhakimiakrmj@gmail.com>

@danbugs danbugs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is AWESOME!! Thank you so much for the contribution! Just ggot some comments here and there for you to consider.

Comment thread docs/host_functions.md Outdated
| `--net-block HOST_OR_IP` | Block-list; all other destinations allowed (implies `--net`). Mutually exclusive with `--net-allow`. |
| `--port PORT` | Allow `net_bind` / listen on `PORT` (implies `--net`). Without `--port`, outbound-only: bind is rejected. |
| `--enable-tools` | Enables custom tool registration. Registers a built-in `echo` tool (used by the `python-tools` example). Library users add their own tools via `SandboxBuilder::tool()`. |
| `--enable-tools` | Registers a built-in `echo` tool (used by the `python-tools` example). Library users add their own tools via `SandboxBuilder::tool()`. |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we'll have this feature, I think --enable-tools should no longer register the built-in echo tool. Instead, we replace that w/ two things: (1) a library usage example (prob a test?) showing how someone can register smt like an echo tool, and (2) we should update the python-tools example to use a echo tool coming from Wasm. For this, let's maybe an example/wasm-host-fns w/ some code that can be compiled to an echo.wasm or smt like that?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is still missing. Could you remove the hardcoded echo tool and make it a Wasm host function tool instead? Then, if it doesn't exist already, once we remove it, let's make sure there's still test coverage for registering host function tools like we did for the echo one too.

Comment thread docs/host_functions.md Outdated
Comment thread docs/host_functions.md
Comment thread docs/host_functions.md Outdated
Comment thread host/src/main.rs
Comment thread host/src/wasm_host_fns.rs Outdated
Comment thread host/src/wasm_host_fns.rs
cachebag added 2 commits June 11, 2026 22:04
Signed-off-by: Akrm Al-Hakimi <alhakimiakrmj@gmail.com>
Signed-off-by: Akrm Al-Hakimi <alhakimiakrmj@gmail.com>

@danbugs danbugs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM. I think this should be good to merge after addressing the echo tool comment. Thanks!

Comment thread host/src/main.rs
use std::path::PathBuf;

#[cfg(feature = "wasm-host-fns")]
mod wasm_host_fns;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is private. I wonder if it should be available to the library too 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expand --enable-tools to support user-provided host functions

3 participants