DESIGN · PLUGINS

Plugins: sandboxed WebAssembly decoders

The short version

Say a stranger offers to translate a foreign instrument's messages for you. You hand them a slip of paper with the bytes on it. They sit in a sealed room with no door, no phone and no window, write numbers on a card and slide it back through a slot. That is all they can do. If they fall asleep or go wild, you close the room and carry on.

A Sawbones plugin is that translator. It is a small program that reads a captured frame of bytes from a device and returns numbers. It cannot read files, open connections, tell the time or ask for anything else. Its answer is treated as untrusted data, like everything else the agent sees.

What a plugin can and cannot do

The v0 plugin kind is a data-first decoder: bytes in, numbers out. A plugin does not offer tools of its own to the agent and cannot name a trust label, a unit or a quantity in text. It returns a quantity index into a manifest the host already holds, plus an integer and a power-of-ten exponent. There are no floating-point numbers and no strings anywhere in the plugin interface.

Many devices do not need code at all. sawbones-regmap describes a device as a TOML register map: address, width, type, scale, unit, valid range and, for writable registers, the hazard class. It refuses anything ambiguous or unsafe, such as overlapping registers or a writable register with no class. An agent's fix to a decoder is then a corrected fact instead of new code.

How the sandbox works (technical)

The host is sawbones-plugin-host. A plugin is a WebAssembly component (WASI 0.2 component model) run by wasmtime.

Admission. Before anything runs, the host scans the component and refuses it if it has any import at all, a nested component, a start function, a canonical built-in other than lift, an export other than decode, or a size over the committed limits. The interface is defined in decoder.wit. A catalog lint checks that plugin worlds contain no text types.

A child process per batch. The host spawns sawbones-plugin-runner bare: empty environment, working directory /, no arguments, stderr discarded. The child then:

  1. Is killed if the host dies, and is made non-dumpable so a same-user process cannot read its memory.
  2. Sets resource limits: no file writes, no new processes or threads, capped descriptors, address space and CPU time.
  3. Builds the wasmtime engine, then installs a seccomp allow-list before it reads the plugin's bytes. Any system call outside the list kills the process. No file can be opened, no socket created, no execve, no ptrace.
  4. Re-checks that the compiled component imports nothing, and instantiates it with a linker that defines nothing.
  5. Runs each frame in a fresh store with a fuel limit, a memory cap, a table cap and an instance cap. The host kills the child at a wall-clock deadline.

Hostile replies. The child's output is parsed as hostile input: bounded in size, with exact lengths. Each value is checked against the host's decoder manifest and becomes an observation with no trust tier. A crash, trap, loop or allocation storm ends in a typed fault for that frame, and the host carries on.

Memory safety. Every host crate in the workspace forbids unsafe code. The sample plugin in plugins/sample-decoder is built for the WebAssembly target and does use unsafe, because a plugin with no imports needs a static arena. It runs inside the sandbox above.

What is built, and what is not

Built and tested: admission checks, the runner and its seccomp sandbox on Linux (x86-64 and aarch64), the register-map decoder and a sample plugin.

Not built yet: a separate unprivileged user for the child, namespaces, Landlock and cgroups (tracked in issue 177). We do not rely on those until they can be tested on the real Pi kernel. Plugin kinds beyond decoders are not designed in detail.

Our decision log also requires every agent-written plugin change to get a second, clean-room review by a separate model before merge. That is a project rule, not a feature of the sandbox.

Read more

The plugin host pull request and the lab note on how the sandbox was built.