Wasmtime
A fast, secure, and standards-compliant WebAssembly runtime — run .wasm binaries from the command line or embed the runtime in your own application.
Wasmtime is a standalone WebAssembly runtime developed by the
Bytecode Alliance. It runs standard .wasm
binaries from the command line and provides a high-quality embeddable runtime
library for use in Rust, C, Python, Go, and other languages. It is one of the
most complete and standards-conformant WebAssembly runtimes available, with full
support for WASI (the WebAssembly System Interface) and cutting-edge proposals
like the Component Model.
Features
- Standards-conformant — passes the full WebAssembly spec test suite; implements WASI, WASI Preview 2, and the Component Model
- Fast compilation — uses the Cranelift code generator for near-native execution speed, with an optional Winch baseline compiler for faster cold starts
- Secure sandbox — WebAssembly's memory isolation model means guest code cannot access host resources unless explicitly granted; Wasmtime enforces this rigorously
- Multi-language embedding — official crates and bindings for Rust, C/C++, Python, Go, .NET, and Ruby
- Caching — compiled modules are cached to disk so subsequent invocations start instantly
- Fuel metering — optionally limit how many instructions a module can execute, useful for untrusted code sandboxing
- Epoch interruption — cooperatively interrupt running WebAssembly modules from the host
- Component Model — first-class support for the WebAssembly Component Model
and
wit-bindgen, enabling strongly-typed interfaces between components
Installation
cargo install wasmtime-cli
Or download a pre-built binary from the releases page:
# macOS
brew install wasmtime
# Arch Linux
pacman -S wasmtime
# Debian / Fedora
# Official install script (works on all Linux distributions):
curl https://wasmtime.dev/install.sh -sSf | bashUsage
Running a WebAssembly module
# Run a .wasm file
wasmtime hello.wasm
# Pass arguments to the wasm program
wasmtime my-cli.wasm -- --flag value
# Run with WASI filesystem access (grant access to a directory)
wasmtime --dir . my-program.wasm
# Run with environment variables
wasmtime --env FOO=bar my-program.wasm
# Run a specific exported function
wasmtime --invoke my_function module.wasmCompiling ahead of time
# Pre-compile a .wasm file to a native .cwasm (cached compiled module)
wasmtime compile module.wasm -o module.cwasm
# Run the pre-compiled module (starts instantly, no JIT warmup)
wasmtime module.cwasmInspecting modules
# Show the exports of a WebAssembly module
wasmtime explore module.wasm
# Run the WebAssembly spec interpreter on a .wat (text format) file
wasmtime foo.watBuilding WebAssembly programs for Wasmtime
Any language that can target wasm32-wasip1 or wasm32-wasip2 works with
Wasmtime. For Rust:
# Add the WASI target
rustup target add wasm32-wasip1
# Build your project for WASI
cargo build --target wasm32-wasip1 --release
# Run the output with wasmtime
wasmtime target/wasm32-wasip1/release/my-program.wasmEmbedding Wasmtime in Rust
cargo add wasmtime wasmtime-wasiuse wasmtime::*;
use wasmtime_wasi::WasiCtxBuilder;
fn main() -> anyhow::Result<()> {
let engine = Engine::default();
let module = Module::from_file(&engine, "module.wasm")?;
let wasi = WasiCtxBuilder::new()
.inherit_stdio()
.inherit_args()?
.build();
let mut store = Store::new(&engine, wasi);
let mut linker = Linker::new(&engine);
wasmtime_wasi::add_to_linker(&mut linker, |s| s)?;
let instance = linker.instantiate(&mut store, &module)?;
let run = instance.get_typed_func::<(), ()>(&mut store, "_start")?;
run.call(&mut store, ())?;
Ok(())
}The Component Model
Wasmtime has first-class support for the WebAssembly Component Model, which enables composable, language-agnostic modules with strongly-typed interfaces defined in WIT (WebAssembly Interface Types):
# Install the tooling
cargo install wasm-tools
cargo install wit-bindgen-cli
# Run a component
wasmtime run --wasm component-model my-component.wasm
The Component Model is the foundation for ecosystems like WASI 0.2 and plugin systems in tools like Zed, Lapce, and Zellij.