Introducing erlang_wasm: a WebAssembly runtime built on the BEAM

Hi everyone,

erlang_wasm 0.10.1 is now available on Hex. Since this is the first post about the project here, a short introduction might be useful.

erlang_wasm is a WebAssembly runtime written in Erlang. It decodes, validates and executes Wasm directly on the BEAM, without Wasmtime or another native engine. Only a small optional NIF is used for secure filesystem operations.

The goal is to run code you don’t control, such as plugins, user scripts or AI-generated code, inside an Erlang or Elixir application. Each execution runs in its own Erlang process, with resource limits and OTP supervision.

The runtime supports WebAssembly 3.0, the Component Model, WASI 0.1/0.2/0.3, and JavaScript, Python and Lua through WebAssembly runtimes. It also has a compiled execution tier that translates Wasm functions into Core Erlang and loads them as BEAM modules.

It currently passes all 65,481 assertions of the official WebAssembly core specification test suite.

What’s new in 0.10?

  • WASI 0.3, including asynchronous components, typed streams, futures, cancellation and HTTP handlers. Wasmtime interoperability tests are also part of CI.

  • Component snapshots, allowing initialized components to be restored per request using copy-on-write memory. Particularly useful for CPython and QuickJS, where startup can be expensive.

  • Faster compiled execution. Calls between compiled functions are now regular BEAM local calls. Recursive fib(30) is 4.7x faster, reaching performance comparable to Wasmtime on this benchmark.

  • Hardening, with stricter resource limits, safer HTTP defaults and improved cleanup. Version 0.10.1 also fixes a WASI filesystem path issue.

Check the demo examples

The wasm_demo repository includes a checkout service where merchants can write their own discount rules in JavaScript.

Each merchant has supervised WebAssembly workers. Rules can be updated live, with execution deadlines and isolation between merchants. A failing rule does not interrupt other checkouts.

This illustrates one of the main ideas behind erlang_wasm: making Erlang applications programmable without introducing separate sandbox infrastructure.

There is still work ahead, particularly on performance and interoperability. Exploring how far a WebAssembly runtime can go using Erlang itself has been quite interesting, with some design choices different from native runtimes.

Feedback and contributions are welcome, especially from anyone interested in WebAssembly, sandboxed execution or plugin systems on the BEAM.

The project is open source under Apache-2.0 and requires Erlang/OTP 29.

Source: GitHub - benoitc/erlang_wasm: A WebAssembly runtime implemented in Erlang/OTP · GitHub

Demo: GitHub - benoitc/wasm_demo: A small project using erlang_wasm: a module from text, a host callback, and a QuickJS worker · GitHub

Release: Release 0.10.1 · benoitc/erlang_wasm · GitHub

3 Likes