Skip to main content

LoadedWasmSandbox

Struct LoadedWasmSandbox 

Source
pub struct LoadedWasmSandbox { /* private fields */ }
Expand description

A sandbox that has both a Wasm engine and an arbitrary Wasm module loaded into memory.

LoadedWasmSandboxes are ready to execute guest code and can execute a guest call, with call_guest_function, multiple times. Each call to call_guest_function executes in the same memory context. If you want to “reset” the memory context, create a new LoadedWasmSandbox – either from another WasmSandbox or by calling my_loaded_wasm_sandbox.devolve()?.evolve()?

Implementations§

Source§

impl LoadedWasmSandbox

Source

pub fn call_guest_function<Output: SupportedReturnType>( &mut self, fn_name: &str, params: impl ParameterTuple, ) -> Result<Output>

Call the function in the guest with the name fn_name, passing parameters params.

On success, return an Ok with the return value and a new copy of Self suitable for further use. On failure, return an appropriate Err.

§Errors

Returns Err(HyperlightError::PoisonedSandbox) if the sandbox is in a poisoned state. Use restore() to recover a poisoned sandbox before calling this method again.

Note: A sandbox becomes poisoned when a previous call fails due to abnormal guest execution. That call returns the original error (e.g., ExecutionCanceledByHost from interrupt_handle().kill(), or errors from guest panics, memory violations, etc.), and the sandbox is marked as poisoned. This method then returns PoisonedSandbox on subsequent calls until the sandbox is recovered.

Source

pub fn snapshot(&mut self) -> Result<Arc<Snapshot>>

Take a snapshot of the current state of the sandbox.

The snapshot can later be used with restore() to return the sandbox to this state.

§Errors

Returns Err(HyperlightError::PoisonedSandbox) if the sandbox is in a poisoned state. Use restore() with a previously taken snapshot to recover before taking a new snapshot.

Source

pub fn restore(&mut self, snapshot: Arc<Snapshot>) -> Result<()>

Restore the state of the sandbox to the state captured in the given snapshot.

This method clears the poisoned state if the sandbox was poisoned, making it usable again for guest function calls.

§Recovery from poisoned state

If a sandbox becomes poisoned (e.g., after interrupt_handle().kill()), calling restore() with a valid snapshot will:

  1. Clear the poisoned state
  2. Reset memory to the snapshot state
  3. Allow subsequent call_guest_function() calls to succeed
Source

pub fn unload_module(self) -> Result<WasmSandbox>

Unload the wasm module and return a WasmSandbox that can be used to load another module.

This method defers calling restore() to reset the sandbox to its pre-module state until a new module is loaded. However, the sandbox will always be restored when a new module is loaded, so a poisoned sandbox can be recovered by unloading and reloading a module.

Source

pub fn interrupt_handle(&self) -> Result<Arc<dyn InterruptHandle>>

Get a handle to the interrupt handler for this sandbox, capable of interrupting guest execution.

Source

pub fn status(&self) -> Result<SandboxStatus>

Get the current lifecycle state of the sandbox.

§Errors

Returns an error if the sandbox is in an invalid state.

Source

pub fn is_poisoned(&self) -> Result<bool>

👎Deprecated since 0.15.0:

use status().is_poisoned() instead

Check if the sandbox is in a poisoned state.

A sandbox becomes poisoned when guest execution does not complete normally, such as after:

  • Forced termination via interrupt_handle().kill()
  • Guest panic or abort
  • Memory violation
  • Stack or heap exhaustion

Note: The call that causes poisoning returns the original error (e.g., ExecutionCanceledByHost), not PoisonedSandbox. The sandbox is marked as poisoned after that error, and subsequent calls to call_guest_function() will return Err(HyperlightError::PoisonedSandbox).

A poisoned sandbox cannot execute guest functions until recovered via restore(). Calling unload_module() will also recover a poisoned sandbox since it performs a restore internally.

§Returns
  • Ok(true) if the sandbox is poisoned and needs recovery
  • Ok(false) if the sandbox is healthy and can execute guest functions
  • Err if the sandbox is in an invalid state

Trait Implementations§

Source§

impl Callable for LoadedWasmSandbox

Source§

fn call<Output: SupportedReturnType>( &mut self, func_name: &str, args: impl ParameterTuple, ) -> Result<Output>

Call a guest function dynamically
Source§

impl Debug for LoadedWasmSandbox

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for LoadedWasmSandbox

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more