Skip to main content

Module wasi_sandbox

Module wasi_sandbox 

Source
Expand description

Profile B (#506): a WASI (wasm32-wasip1) sandbox whose ENTIRE filesystem is a Subject-scoped [hyprstream_vfs::Mount] — and nothing else.

Contrast with Profile A (crate::Sandbox): Profile A is a bespoke capability Linker granting ONLY env::host_random + env::vfs_*, zero WASI. Profile B grants a REAL WASI preview1 surface (so an off-the-shelf wasm32-wasip1 guest that does open/read/write/readdir runs unmodified) — but every WASI filesystem op is routed to a MountDir backed by the VFS Mount. The make-or-break property: the VFS is the guest’s ONLY filesystem. There is no host preopen.

§The hard caveat — capability withholding

A single host preopen or any ambient WASI capability that touches the host reopens the sandbox escape. So the Profile-B [wasi_common::WasiCtx] is built by hand (NOT via sync::WasiCtxBuilder, which only does cap_std::fs::Dir host preopens):

  • Preopen set: EXACTLY ONE — the VFS MountDir at guest path /. No preopened_dir(host_dir), ever.
  • Clocks: withheld. WasiClocks::new() leaves both system + monotonic None; any clock_time_get/clock_res_get returns badf (a future revision can VFS-mediate a clock file). The crate::EpochTimer is the DoS bound, not a guest-visible clock.
  • Randomness: withheld from the host OS. The ctx random source is wasi_common::random::Deterministic (NOT OS entropy); random_get yields a deterministic stream, not host CSPRNG output.
  • Scheduling: [DeniedSched] — poll_oneoff/sched_yield/sleep all error (deny-by-default).
  • stdio: the [WasiCtx::new] default — stdin = empty, stdout/stderr = sink. No host fd inheritance.
  • wasi:sockets, environ, args: none. preview1 has no sockets; environ/args are left empty.

The bound Subject is fixed at construction and threaded by MountDir into every Mount call — the Mount is the ONE policy enforcement point.

Structs§

WasiSandbox
A Profile-B WASI sandbox: a wasm32-wasip1 guest whose filesystem is a Subject-scoped VFS [Mount].
WasiState
Per-call host state for a Profile-B Store: the bound Subject + the WASI ctx (whose only preopen is the VFS MountDir).