wasmer

A fast, secure WebAssembly runtime crate for embedding sandboxed Wasm and WASIX modules directly inside Rust programs.

Library
Cargo
v7.3.0
20,989stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
91/100Excellent
Development Activity100
Maintenance100
Community64
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
89/100Excellent
Architecture90
Code Quality92
Innovation88
Learning Curve85

Wasmer is the embeddable Rust API at the heart of the Wasmer WebAssembly runtime, published to crates.io as the wasmer crate. It lets a Rust application load a .wasm module, instantiate it inside a Store, wire up host functions through an imports! object, and call exported functions with full type safety — all without giving the guest module any file, network, or environment access unless it’s explicitly granted.

The crate supports multiple execution backends behind one API: the sys flavor runs WebAssembly through pluggable compilers (Cranelift for balanced dev-time performance, LLVM for near-native production speed, Singlepass for fast startup and deterministic gas metering), while the js flavor lets the same Rust code compile to WebAssembly and run inside a browser or Node.js host using the environment’s own engine. It also underpins WASIX, an extended WASI-like interface for networking, threads, and process control in sandboxed modules.

What You Get

  • Store/Module/Instance API - the core embedding primitives for compiling a .wasm module and instantiating it with host imports.
  • Three pluggable compilers - Singlepass (fastest compile time), Cranelift (balanced default), and LLVM (fastest runtime, ~50% faster than Cranelift) selectable via feature flags.
  • Headless mode - deserialize a pre-compiled module and run it without a compiler linked in, for constrained or fast-start environments.
  • Cross-compilation support - compile a module ahead of time for a different target architecture or OS, then run it there later.
  • js backend for WebAssembly-of-WebAssembly - compile the same Rust embedding code to Wasm itself and run it inside a browser or Node.js host, delegating to the host’s own JS engine.
  • WASIX integration - opt into an extended WASI interface (via wasmer-wasix) adding networking, threads, and process spawning for sandboxed modules that need more than plain WASI offers.

Common Use Cases

  • Plugin systems - let a Rust host application load untrusted third-party plugins compiled to WebAssembly and run them in a capability-sandboxed Store.
  • Server-side function execution - run user-submitted or multi-tenant code paths as WebAssembly modules with predictable resource limits via metering middleware.
  • Edge and serverless runtimes - use headless mode with pre-compiled modules for fast cold starts in constrained deployment environments.
  • Cross-platform native app extensions - ship one WebAssembly module and run it unmodified across the architectures Wasmer’s compilers target.
  • Blockchain and smart-contract execution - deterministic, gas-meterable execution via the Singlepass compiler for on-chain or verifiable computation.

Under The Hood

Architecture The wasmer crate (lib/api) is the public embedding surface over a much larger Cargo workspace: it re-exports and coordinates wasmer-vm (the low-level virtual machine), wasmer-compiler plus the three backend crates (wasmer-compiler-cranelift, -llvm, -singlepass), and wasmer-types for the shared type system, while an entirely separate js backend under src/backend/js lets the same public API compile to WebAssembly and delegate to a host JS engine instead of linking a native VM at all. Inside src/entities/ each Wasm concept — Module, Instance, Function, Memory, Table, Global, Store, Exports, Imports — gets its own module, and a backend enum abstraction (src/backend/mod.rs) lets the same entity types dispatch to sys, js, or v8 implementations depending on which Cargo features are enabled, so swapping the execution backend doesn’t change any calling code. Optional integrations (wasmer-wasix for WASIX, wasmer-middlewares for metering) plug in as separate workspace crates rather than being baked into the core API.

Tech Stack The crate is pure Rust (edition 2024, MSRV 1.95) built with Cargo workspace tooling across dozens of member crates. Core mandatory dependencies are indexmap, thiserror, bytes, and tracing; the sys backend adds target-lexicon for cross-target support, dashmap for concurrent state, and optional corosensei/futures for async execution paths. The three compiler backends are separate optional dependencies gated by Cargo features (cranelift, llvm, singlepass), and webc (Wasmer’s own package format crate) plus wasmer-config and wasmer-package handle the broader Wasmer package ecosystem beyond just raw .wasm execution. CI (.github/workflows/) runs a dedicated build, test, benchmark, and public-API-diff pipeline (check-public-api.yaml) on every change, alongside cross-compiler and multi-arch build matrices.

Code Quality The workspace has an extensive, multi-layered test suite: unit tests colocated with the API crate under lib/api/tests, a full compiler conformance suite under tests/compilers, WASI/WASIX conformance fixtures under tests/c-wasi-tests and tests/rust-wasi-tests, integration tests under tests/integration, and the official WebAssembly spec test suite under tests/wast. lib.rs enables #![deny(missing_docs, ...)] and a set of #![warn(clippy::...)] lints (float_arithmetic, map_unwrap_or, print_stdout, use_self), and error handling is explicit via thiserror-derived error enums rather than panics or swallowed results. A check-public-api.yaml CI job specifically guards against unintentional breaking changes to the crate’s public surface — an unusually rigorous practice for an open-source library.

API Design The public API mirrors the WebAssembly spec’s own object model closely (Store, Module, Instance, Function, Memory, Table, Global), so anyone who has read the WebAssembly core spec can map concepts directly onto Rust types with minimal translation. The imports! macro reduces host-function wiring boilerplate to a declarative block, and the crate ships an extensive examples/ directory (hello-world, imports/exports, memory growth, metering, cross-compilation, headless mode) alongside doc-tested code samples directly in lib.rs, so getting from zero to a running module takes only a handful of lines. The tradeoff is a large feature-flag surface (sys vs js vs v8, per-compiler flags) that a newcomer has to understand before picking the right Cargo.toml configuration for their target environment.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search