Skip to main content

Sandbox

Struct Sandbox 

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

A loaded, ready-to-run sandbox over a single guest module, bound to one Subject.

Constructing a Sandbox binds it to a Subject; every call on it runs as that Subject. Two Sandboxes bound to different Subjects keep independent Store identity (no shared global/thread-local state) — see the subject_isolation test.

This is the GENERIC Profile-A core: call_export ships a byte payload to a named guest export over the guest’s alloc/memory ABI. Language profile crates (e.g. hyprstream-workers-python) build typed APIs on top of it.

Implementations§

Source§

impl Sandbox

Source

pub fn from_bytes(wasm: &[u8]) -> Result<Self>

Load a guest module from raw wasm bytes, bound to the anonymous subject.

Source

pub fn from_bytes_for(wasm: &[u8], subject: Subject) -> Result<Self>

Load a guest module from raw wasm bytes, bound to subject.

Source

pub fn with_vfs(self, handle: VfsProxyHandle) -> Self

Grant this sandbox a Subject-scoped VFS capability (env::vfs_*).

The handle should be a vfs::VfsProxyHandle from spawn_vfs_proxy(ns, subject) with the SAME subject the sandbox is bound to, so the capability is scoped to this sandbox’s identity. Builder-style.

Source

pub fn subject(&self) -> &Subject

The subject this sandbox is bound to.

Source

pub fn call_export(&self, name: &str, input: &[u8], fuel: u64) -> Result<i32>

Call the named guest export with input shipped into guest memory, under the given fuel budget.

This is the GENERIC Profile-A entry point. It instantiates a fresh guest instance, allocates a buffer via the guest’s alloc export, writes input into it, calls export(ptr, len) -> i32, then deallocs the buffer. Returns the export’s i32 status on normal completion, or Err if the guest TRAPPED (e.g. ran out of fuel, or reached an un-granted, trap-wired import). Deterministic (fuel-bounded); the building block profile modules call.

The guest must export alloc(i32)->i32, dealloc(i32,i32), memory, and the named export with signature (i32,i32)->i32.

Source

pub fn engine(&self) -> &Engine

The engine backing this sandbox. Spawn an EpochTimer on it to enable the wall-clock bound used by epoch-deadline call paths (e.g. Sandbox::call_export_with_epoch).

Source

pub fn call_export_with_epoch( &self, name: &str, input: &[u8], ticks: u64, ) -> Result<i32>

Like call_export but bounded by a WALL-CLOCK epoch deadline of ticks epoch increments instead of fuel.

This is the PRODUCTION DoS bound: paired with an EpochTimer spawned on engine ticking every t, the guest traps with “interrupt” after roughly ticks * t of wall time. Fuel is set effectively infinite so the epoch (not fuel) is the limiter. The caller owns the EpochTimer; this method does not start one. Generic over the named (i32,i32)->i32 export — language profiles (e.g. python eval) drive their entry through it.

Source

pub fn open_instance(&self, per_call_fuel: u64) -> Result<PersistentInstance>

Open a PERSISTENT guest instance over this sandbox for the packed-op ABI.

Unlike call_export (a fresh instance per call), the returned PersistentInstance holds ONE long-lived Store + Instance, so guest interpreter state survives across calls. This is the generic substrate a language profile (e.g. the python shell’s persistent interpreter, whose /lang/python/vars + /defs semantics depend on persistence) builds on.

per_call_fuel is applied per PersistentInstance::call_op (a fresh budget each invocation); the store itself is reused. The epoch is pushed out (fuel is the limiter for this path). The guest must export alloc(i32)->i32, dealloc(i32,i32), memory, and the packed-op export named in call_op.

Source

pub fn probe_vfs(&self, op: i32, path: &str, body: &[u8]) -> Result<VfsReply>

Drive the guest’s vfs_probe export: make the GUEST call an env::vfs_* host fn, proving the capability is real end-to-end (guest -> host fn -> Subject-scoped proxy -> Namespace).

op: 0=cat, 1=ls, 2=echo, 3=ctl. path + optional body (echo/ctl). Returns the decoded [status][payload] reply the host fn produced — the minimal “a guest call against a VFS path goes through the Mount” exercise of the env::vfs_* capability.

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> GetSetFdFlags for T

§

fn get_fd_flags(&self) -> Result<FdFlags, Error>
where T: AsFilelike,

Query the “status” flags for the self file descriptor.
§

fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>
where T: AsFilelike,

Create a new SetFdFlags value for use with set_fd_flags. Read more
§

fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>
where T: AsFilelike,

Set the “status” flags for the self file descriptor. Read more
§

impl<T> Instrument for T

§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Pointee for T

§

type Pointer = u32

§

fn debug( pointer: <T as Pointee>::Pointer, f: &mut Formatter<'_>, ) -> Result<(), Error>

§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ServiceExt for T

§

fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>
where Self: Sized,

Apply a transformation to the response body. Read more
§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
§

fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Follow redirect resposes using the Standard policy. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSync for T
where T: Sync,

§

impl<T> MaybeSync for T
where T: Sync,