Skip to content

Add host function registration for Node.js#31

Merged
simongdavies merged 1 commit intomainfrom
add-host-func-to-node
Mar 3, 2026
Merged

Add host function registration for Node.js#31
simongdavies merged 1 commit intomainfrom
add-host-func-to-node

Conversation

@simongdavies
Copy link
Contributor

Add support for registering host-side JavaScript callbacks that guest sandboxed code can call via ES module imports.

New APIs:

  • proto.hostModule(name) - Create a builder for registering functions
  • builder.register(name, callback) - Register a host function
  • proto.register(module, fn, callback) - Convenience method

Guest code imports host modules as 'import * as math from "host:math"' and calls functions like math.add(1, 2). Arguments are JSON-serialized across the sandbox boundary. Both sync and async callbacks are supported.

Changes:

  • hyperlight-js: Add register_raw() for dynamic NAPI scenarios
  • js-host-api: Add HostModule wrapper, ThreadsafeFunction bridge
  • js-host-api: Update Cargo.toml to use tokio_rt feature
  • Add comprehensive tests (22 new JS tests, 4 new Rust tests)
  • Add host-functions.js example
  • Update README with Host Functions documentation

@simongdavies simongdavies added the kind/enhancement New feature or improvement label Mar 3, 2026
Add support for registering host-side JavaScript callbacks that guest
sandboxed code can call via ES module imports.

New APIs:
- proto.hostModule(name) - Create a builder for registering functions
- builder.register(name, callback) - Register a host function
- proto.register(module, fn, callback) - Convenience method

Guest code imports host modules as 'import * as math from "host:math"'
and calls functions like math.add(1, 2). Arguments are JSON-serialized
across the sandbox boundary. Both sync and async callbacks are supported.

Changes:
- hyperlight-js: Add register_raw() for dynamic NAPI scenarios
- js-host-api: Add HostModule wrapper, ThreadsafeFunction bridge
- js-host-api: Update Cargo.toml to use tokio_rt feature
- Add comprehensive tests (22 new JS tests, 4 new Rust tests)
- Add host-functions.js example
- Update README with Host Functions documentation

Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
@simongdavies simongdavies force-pushed the add-host-func-to-node branch from 7ee1036 to ea7a1a0 Compare March 3, 2026 14:04
Copy link
Contributor

@jprendes jprendes left a comment

Choose a reason for hiding this comment

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

LGTM

@simongdavies simongdavies merged commit 754139c into main Mar 3, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement New feature or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants