What Is WebAssembly?
WebAssembly (WASM) is a new type of low-level binary format, like assembly language, designed to be run in a virtual machine. Languages such as C, C++ and Rust can be compiled directly to WebAssembly and run inside the sandbox, providing high performance, deterministic execution, portability across different platforms, and protection against malicious code.
Wasmbox provides a complete WebAssembly runtime for Unity (based on the Wasmtime engine) which can be used to run non-C# code on many platforms, to sandbox malicious or potentially buggy code (e.g. mods) and to provide deterministic execution (e.g. lockstep multiplayer).
WebAssembly is an official W3C standard, completely described in this specification.
Benefits Of WebAssembly
The main benefits of WebAssembly can be understood from the initial design goals laid out in the W3C specification:
- Fast
- None of the other benefits matter if WASM is too slow to use!
- WASM is designed for "near native" performance, currently achieving around 0.75x native speed in benchmarks.
- Safe/Secure:
- All WASM code is validated and executes in a completely memory-safe sandbox.
- No program can break out and access anything outside of the sandbox.
- Deterministic:
- WASM code execution is deterministic, producing the same results every time no matter what hardware it is running on.
- Read more about guaranteed determinism in Wasmbox.
- Cross Platform:
- The same WASM code can be used on many platforms.
- Avoid compiling native dependencies for all 20+ Unity platforms by compiling just to WASM.
- Open:
- The WebAssembly System Interface (WASI) specification extends WASM with safe/secure ways to access resources (e.g. the filesystem).
- Wasmbox includes an implementation of WASI, including a complete "Virtual File System" (in memory).