Browser and WASI boundaries
Quick answer
Browsers expose web APIs through JavaScript and host bindings. WASI defines interfaces through which a compatible runtime can provide selected system capabilities. Neither environment grants arbitrary native operating-system access.
Choose capabilities explicitly
WASI Preview 1 modules can use supported std operations through the runtime, subject to granted resources. A browser module instead relies on browser APIs and permissions. Preview 2 component interfaces differ from Preview 1; runtime support must be checked separately. Sandbox security depends on the runtime, exposed imports and resource limits. Do not equate portability with compatibility of every crate.
Manual local Rust/Cargo candidate; not executed. Expected behavior:
Build with cargo +1.85.0 build --target wasm32-wasip1; run the module with a compatible WASI Preview 1 runtime; expect hello from WASI.Stdout is provided by the runtime, not a built-in Wasm console.
fn read_config(config: Option<&str>) -> Result<&str, &'static str> { config.ok_or("unavailable") }fn main() { println!("{:?} {:?}", read_config(Some("demo")), read_config(None)); }Expected stdout (not executed):
Ok("demo") Err("unavailable")Explicit absence makes it possible to test denied capabilities without a runtime.
Common mistake
Do not grant all host directories simply to make a WASI example run.
Try it yourself
List the minimum capabilities a calculator and a file-conversion tool each need.
Static examples for Rust 1.85.0, edition 2024. Run them locally in a disposable project; ByteMind execution support and these outputs have not been verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Browser and WASI boundaries — practice quiz
Choose one answer per question. Code examples are predictions; review explanations after attempting them.
A WASI module needs one input directory. What is a least-privilege capability policy?
Browser and WASI boundaries — example 1. Read the code; do not execute it for this question. Assume the lesson’s stated setup, compatible dependencies and toolchain, and a fresh disposable directory for file-creating examples. ```rust fn main() { println!("hello from WASI"); } ``` Which outcome or interpretation best matches this example?
Browser and WASI boundaries — example 2. Read the code; do not execute it for this question. Assume the lesson’s stated setup, compatible dependencies and toolchain, and a fresh disposable directory for file-creating examples. ```rust fn read_config(config: Option<&str>) -> Result<&str, &'static str> { config.ok_or("unavailable") } fn main() { println!("{:?} {:?}", read_config(Some("demo")), read_config(None)); } ``` What standard output should the program produce if its run succeeds? Ignore Cargo and diagnostic messages.