Guest ABI v2
This page is for people who write a guest toolchain or its glue. It states what the runtime requires of a module and what it provides, so you can build to the contract to the letter. It assumes you know WIT and the component model; to write a function, start at Write a module. Grants are on Cedar policy, the Input on the Input reference and the manifest on Module manifests.
A guest is a WebAssembly component targeting a world of the WIT package guestfn:function@1.0.0 (wit/guestfn-function.wit). The payload is Protobuf: RunFunctionRequest bytes in, RunFunctionResponse bytes out. The canonical ABI moves memory, so a guest has no allocator export. ABI v2 is the one ABI the runtime serves.
The world
package guestfn:function@1.0.0;
world function {
enum log-level { debug, info, warn, error }
import log: func(level: log-level, msg: string, kv: list<tuple<string, string>>);
export run: async func(request: list<u8>) -> result<list<u8>, string>;
}
runhandles one request. The host passes the caller’sRunFunctionRequestand returns the guest’sRunFunctionResponse. It decodes and encodes each of them once on the way and keeps every field, including one newer than the runtime’s own copy of the proto, on every message of the function API. The bytes aren’t the caller’s or the guest’s own, so a guest can’t depend on their layout. The host leaves out the step credentials the module wasn’t granted, and the pull credential in every case.runisasync, so a guest may await its imports,wasi:httpamong them. The run’s deadline applies while it does, less the time it waits for the host’s HTTP answer. A sync-liftedrunalso satisfies the world, because the canonical ABI accepts a sync function where an async one is expected.logis structured logging through the host, with typed values. The host attaches the module’s identity to every line and renders it at the runtime’s level of the same name.debuglines appear under--debugalone.- The runtime typechecks
log-levelto the letter, sologchanges with2.0.0alone. function-sync, the package’s second world, is this contract withrundeclared sync, for a toolchain that can’t async-lift it. The runtime checks every guest againstfunction.
WASI and the sandbox
The world doesn’t import WASI. A guest brings whatever its toolchain emits, and the host links both WASI generations:
- WASI 0.2: components built by jco, componentize-py or Rust’s
wasm32-wasip2, and a guest that importswasi_snapshot_preview1, the Go scaffold’s, through the wasip1 adapterguestfn buildlinks in. - WASI 0.3: a
wasm32-wasip3build.
The engine accepts WebAssembly 2.0 plus the extended-const and
relaxed-simd proposals. Relaxed SIMD runs with its deterministic semantics,
and a module computes the same result on every host. The engine refuses the
other WebAssembly 3.0 proposals at compile: threads, GC, function references,
exceptions, tail calls, multi-memory and memory64. No guest toolchain in the matrix emits any of
them (every scaffold and example was measured with wasm-tools validate on
2026-10-28), and a proposal can be enabled later as a minor.
The sandbox allows:
- no network sockets;
- no filesystem beyond the granted private
/tmp, the one pre-opened directory; - environment as granted, with nothing added;
argvis["function"].
The three-layer decision grants these capabilities. limits and the deadlines apply to every run. limits.timeout bounds the time of a run, not counting the time it waits for the host’s HTTP answer. The request’s gRPC deadline is the hard cap. Sleeping or blocking in another WASI call spends that budget too, and the run ends at the deadline whether the guest is executing or not. A component has no top-level memory export, and the host reserves nothing from --max-total-run-memory before the run. It charges the whole footprint as the guest claims its memories, and a growth the pool can’t serve fails inside the run: memory.grow returns -1.
HTTP egress
A guest sends HTTP requests through wasi:http/client@0.3.0 (send: async func) or wasi:http@0.2’s outgoing-handler, which componentize-js’s fetch() uses. One host bridge serves both. The runtime’s egress client performs each send or refuses it under the grant. The policy is on HTTP egress.
- Bodies are complete on both sides, and the response budget applies to whole responses.
- The guest receives a host-reported failure as the
internal-errorcode, whose payload is the refusal string, for a grant refusal, a blocked address, an exhausted budget or a transport failure. The wording is contract, held by the conformance goldens. - The time a guest waits for the host’s HTTP answer is credited back to its deadline.
Errors
A guest that can produce a response encodes failures into it as a fatal Result. run returning err(string) is for failures before a response can be built, such as a codec that can’t decode the request. The host turns it into the request’s fatal result: module <desc> failed: run returned an error: <string>.
Traps, WASI exits, deadline interrupts and memory denials are fatal results from the host that name the module, never gRPC errors:
run failed: trap: …run failed: module exited with status Nrun failed: module exceeded its execution deadline (…)
Detection
The runtime reads the binary format from the first eight bytes of the module. A component (layer 1 in the WASM header) is loaded and typechecked against the world. A core module (layer 0) is refused with one sentence, whatever it exports:
module is a core module, which function-wasm 1.0.0 no longer runs (ABI v1 was removed); build it as an ABI v2 component (docs/abi-v2.md)
The runtime reports it as a fatal result (cannot load module <desc>: …), and guestfn build, guestfn inspect and function validate --resolve print the same sentence. Detection has no flag and no Input field.
A typecheck refusal begins component does not implement the guestfn:function@1.0.0 world: ….
A module manifest declares contract: wasm@1.0, this world. Another version is refused before the module is looked at: contract wasm@0.9 is not one the wasm engine implements: wasm@1.0.
Versioning
guestfn:function@1.0.0 is the contract from function-wasm 1.0.0 on. The world’s version moves on its own, by what a change asks of guests:
- A 1.x minor may add imports and nothing else: a new interface or a new function. A component imports what it uses and nothing more. The runtime serves a guest built against an earlier 1.x unchanged. A guest that imports the addition declares the contract minor that added it, and a runtime that doesn’t offer that contract refuses it by name.
- Within 1.x,
run’s signature, thelogimport (thelog-levelcases included) and anything else already in the world stay as they are. Changing or removing any of them is2.0.0, a world every guest is rebuilt against. - A new field of
RunFunctionRequestorRunFunctionResponsemoves no world version. Payload evolution is Protobuf’s.
A guest declares the WASI 0.2 or 0.3 interfaces it imports in wit/world.wit, at the versions the wasmtime-wasi-http release the runtime builds on links. The release notes list the WASI versions the runtime links. A guest built against an older set keeps running while those versions are linked, and otherwise fails the world typecheck at load.
Getting the world
Guest toolchains read a local wit/ directory, so guestfn build fills it. A guest commits wit/world.wit and guestfn.lock, which pins the digest of every package the guest builds against, and wit/deps/ stays out of version control.
The guest’s own world, wit/world.wit in a local:guest package, includes one of the two worlds beside whatever else the guest imports:
package local:guest;
world function {
include guestfn:function/function-sync@1.0.0;
import wasi:http/outgoing-handler@0.2.12;
}
guestfn init writes both files. The rust scaffold includes function. The go, ts and python scaffolds and the C, C++, Zig, Odin, MoonBit and C# examples include function-sync, the signature their toolchains take today.
Publication
Publish WIT (publish-wit.yml), run by hand from a wit-v<version> tag, publishes the package, signed and attested, as an OCI artifact in the CNCF Wasm OCI layout, the format of wkg: ghcr.io/jonasz-lasut/guestfn/function:<version>. A published version is never pushed again.
guestfn wit update bumps a guest to a published version. It installs the newest version of the major the guest’s include declares, or the version --version names, and moves the version in the include in wit/world.wit. It also writes the WASI packages the world imports, at the versions the world declares, and everything those refer to, from ghcr.io/webassembly/wasi. guestfn.lock pins every package’s digest. Regenerate any bindings you check in afterward. --dir names the project, and --repository and --wasi-repository name mirrors.
With a guestfn.lock present, guestfn build pulls the pinned digests, no others, into wit/deps/ before it calls the toolchain, and a copy that changed is written back. guestfn wit fetch does the same for a build that doesn’t go through guestfn build. A project with no lock keeps the copy it has.
To fetch the package with wkg instead, map the namespace in its configuration:
[namespace_registries]
guestfn = { registry = "guestfn", metadata = { preferredProtocol = "oci", "oci" = { registry = "ghcr.io", namespacePrefix = "jonasz-lasut/" } } }
wkg get guestfn:function@1.0.0 --format wit then writes guestfn_function@1.0.0.wit, the file a guest that doesn’t use guestfn keeps under wit/deps/.