Skip to main content

hyperlight_js/
lib.rs

1/*
2Copyright 2026  The Hyperlight Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16//! This crate provides a Hyperlight implementation for JavaScript guest code.
17#![deny(dead_code, missing_docs, unused_mut)]
18#![cfg_attr(not(any(test, debug_assertions)), warn(clippy::panic))]
19#![cfg_attr(not(any(test, debug_assertions)), warn(clippy::expect_used))]
20#![cfg_attr(not(any(test, debug_assertions)), warn(clippy::unwrap_used))]
21#![cfg_attr(any(test, debug_assertions), allow(clippy::disallowed_macros))]
22
23mod resolver;
24mod script;
25
26/// Sandbox module containing all sandbox-related types
27pub mod sandbox;
28
29use hyperlight_host::func::HostFunction;
30/// A Hyperlight Sandbox with a JavaScript run time loaded but no guest code.
31pub use sandbox::js_sandbox::JSSandbox;
32/// A Hyperlight Sandbox with a JavaScript run time loaded and guest code loaded.
33pub use sandbox::loaded_js_sandbox::LoadedJSSandbox;
34/// A Hyperlight Sandbox with no JavaScript run time loaded and no guest code.
35/// This is used to register new host functions prior to loading the JavaScript runtime.
36pub use sandbox::proto_js_sandbox::ProtoJSSandbox;
37/// A builder for creating a new `JSSandbox`
38pub use sandbox::sandbox_builder::SandboxBuilder;
39/// Types for working with JS script.
40pub use script::Script;
41/// The function to pass to a new `JSSandbox` to tell it how to handle
42/// guest requests to print some output.
43pub type HostPrintFn = HostFunction<i32, (String,)>;
44/// The Result of a function call
45pub type Result<T> = hyperlight_host::Result<T>;
46/// Check if there is a hypervisor present
47pub use hyperlight_host::is_hypervisor_present;
48/// Create a generic HyperlightError
49pub use hyperlight_host::new_error;
50/// The error type for Hyperlight operations
51pub type HyperlightError = hyperlight_host::HyperlightError;
52/// A handle to interrupt guest code execution
53pub use hyperlight_host::hypervisor::InterruptHandle;
54/// The container to store the value of a single parameter to a guest
55/// function.
56pub type ParameterValue = hyperlight_host::func::ParameterValue;
57/// The container to store the return value from a guest function call.
58pub type ReturnValue = hyperlight_host::func::ReturnValue;
59/// The type of the return value from a guest function call.
60pub type ReturnType = hyperlight_host::func::ReturnType;
61/// A snapshot of sandbox state that can be used to restore it later.
62pub use hyperlight_host::sandbox::snapshot::Snapshot;
63/// Configuration for sandbox resource limits and behavior.
64pub use hyperlight_host::sandbox::SandboxConfiguration;
65/// Module resolution and loading functionality.
66pub use resolver::{FileMetadata, FileSystem, FileSystemEmbedded, ResolveError};
67/// Execution statistics from the most recent guest function call.
68#[cfg(feature = "guest-call-stats")]
69pub use sandbox::execution_stats::ExecutionStats;
70/// The monitor module — re-exports `sleep` so custom monitors don't couple to tokio directly.
71pub use sandbox::monitor;
72/// CPU time based execution monitor.
73#[cfg(feature = "monitor-cpu-time")]
74pub use sandbox::monitor::CpuTimeMonitor;
75// Execution monitoring
76/// Trait for implementing execution monitors that can terminate handler execution.
77pub use sandbox::monitor::ExecutionMonitor;
78/// Sealed trait for monitor composition — automatically derived for all
79/// `ExecutionMonitor` impls and for tuples of up to 5 monitors.
80pub use sandbox::monitor::MonitorSet;
81/// Wall-clock based execution monitor.
82#[cfg(feature = "monitor-wall-clock")]
83pub use sandbox::monitor::WallClockMonitor;