Skip to main content

hyperlight_js/
lib.rs

1//! This crate provides a Hyperlight implementation for JavaScript guest code.
2#![deny(dead_code, missing_docs, unused_mut)]
3#![cfg_attr(not(any(test, debug_assertions)), warn(clippy::panic))]
4#![cfg_attr(not(any(test, debug_assertions)), warn(clippy::expect_used))]
5#![cfg_attr(not(any(test, debug_assertions)), warn(clippy::unwrap_used))]
6#![cfg_attr(any(test, debug_assertions), allow(clippy::disallowed_macros))]
7
8mod resolver;
9mod script;
10
11/// Sandbox module containing all sandbox-related types
12pub mod sandbox;
13
14use hyperlight_host::func::HostFunction;
15/// A Hyperlight Sandbox with a JavaScript run time loaded but no guest code.
16pub use sandbox::js_sandbox::JSSandbox;
17/// A Hyperlight Sandbox with a JavaScript run time loaded and guest code loaded.
18pub use sandbox::loaded_js_sandbox::LoadedJSSandbox;
19/// A Hyperlight Sandbox with no JavaScript run time loaded and no guest code.
20/// This is used to register new host functions prior to loading the JavaScript runtime.
21pub use sandbox::proto_js_sandbox::ProtoJSSandbox;
22/// A builder for creating a new `JSSandbox`
23pub use sandbox::sandbox_builder::SandboxBuilder;
24/// Types for working with JS script.
25pub use script::Script;
26/// The function to pass to a new `JSSandbox` to tell it how to handle
27/// guest requests to print some output.
28pub type HostPrintFn = HostFunction<i32, (String,)>;
29/// The Result of a function call
30pub type Result<T> = hyperlight_host::Result<T>;
31/// Check if there is a hypervisor present
32pub use hyperlight_host::is_hypervisor_present;
33/// Create a generic HyperlightError
34pub use hyperlight_host::new_error;
35/// The error type for Hyperlight operations
36pub type HyperlightError = hyperlight_host::HyperlightError;
37/// A handle to interrupt guest code execution
38pub use hyperlight_host::hypervisor::InterruptHandle;
39/// The container to store the value of a single parameter to a guest
40/// function.
41pub type ParameterValue = hyperlight_host::func::ParameterValue;
42/// The container to store the return value from a guest function call.
43pub type ReturnValue = hyperlight_host::func::ReturnValue;
44/// The type of the return value from a guest function call.
45pub type ReturnType = hyperlight_host::func::ReturnType;
46/// A snapshot of sandbox state that can be used to restore it later.
47pub use hyperlight_host::sandbox::snapshot::Snapshot;
48/// Configuration for sandbox resource limits and behavior.
49pub use hyperlight_host::sandbox::SandboxConfiguration;
50/// Module resolution and loading functionality.
51pub use resolver::{FileMetadata, FileSystem, FileSystemEmbedded, ResolveError};
52/// The monitor module — re-exports `sleep` so custom monitors don't couple to tokio directly.
53pub use sandbox::monitor;
54/// CPU time based execution monitor.
55#[cfg(feature = "monitor-cpu-time")]
56pub use sandbox::monitor::CpuTimeMonitor;
57// Execution monitoring
58/// Trait for implementing execution monitors that can terminate handler execution.
59pub use sandbox::monitor::ExecutionMonitor;
60/// Sealed trait for monitor composition — automatically derived for all
61/// `ExecutionMonitor` impls and for tuples of up to 5 monitors.
62pub use sandbox::monitor::MonitorSet;
63/// Wall-clock based execution monitor.
64#[cfg(feature = "monitor-wall-clock")]
65pub use sandbox::monitor::WallClockMonitor;