Introducing Yaegi v2, the Most Complete Go Interpreter

In 2019, at Traefik Labs, we created Yaegi to run Go programs without a compile step. It was an exceptional piece of work: at that time, it was the best Go interpreter available. Since then, Yaegi has powered Traefik plugins: with it, you extend your proxy in plain Go, without a rebuild.
Today we go much further. Yaegi v2 is a new engine written from scratch, with one rule: a plugin that is valid Go gives the same result in Traefik as when you compile it. What this means for you:
- Plugins behave like compiled Go, also with libraries that use
reflect. - Most plugins are faster.
- Guardrails limit the effect of a plugin bug on Traefik.
Yaegi v2 comes with Traefik v3.8. It is opt-in: Yaegi v1 is still the default, and you choose which plugins run with Yaegi v2.
Why We Wrote a New Engine
Yaegi v1 has run Traefik plugins for years. It implements the Go language by itself, with its own type checker and its own version of the Go semantics. This was a very large piece of work, and it took Yaegi far. But this design has limits:
- Each new Go feature must be written again by hand: generics, iterators, the Go 1.22 loop variable,
min,max,clear. - Small differences with the Go compiler are hard to avoid. A program can run with Yaegi and not build with
go build, or the opposite. - Native libraries that use
reflectdo not see the interpreted types as they are.encoding/json,fmt,ortext/templatedo not see the methods of a type that only exists in the interpreter. The output can then be different from compiled Go, without an error.
These limits come from the design, not from the quality of the work. To go further, we had to change the design. Yaegi v2 uses the official Go tools to understand the code, and only adds the part that runs it. The details are in the section "How It Works" below.
What Yaegi v2 Brings
Plugins That Behave Like Compiled Go
We wanted a simple rule: if your plugin is valid Go, it gives the same result in Traefik as when you compile it.
To check this, we used Go's own tests. The Go repository has a test suite for the compiler and the runtime. We ran the suite of Go 1.27 with Yaegi v1 (release v0.16.3) and with Yaegi v2:
| Tests of the Go suite | Compiled Go | Yaegi v1 | Yaegi v2 |
|---|---|---|---|
| Programs that run and print the expected output (1066 tests) | 1055 | 641 | 1044 |
Even compiled Go does not pass all 1066 programs: 11 of them depend on the test environment. On this suite, Yaegi v2 passes more programs than any other Go interpreter we tested. The programs that Yaegi v2 does not pass need cgo or test the internals of the Go runtime, and a few are bugs that we track. The result of each test is in the Yaegi repository.
The language was one part of the problem. The other part was reflect.
Go cannot create a named type or a method at runtime. So when interpreted code gives a value to a native library, the library sees a struct without its methods. Take this plugin:
type Status struct{ Code int }
func (s Status) MarshalJSON() ([]byte, error) {
return json.Marshal(fmt.Sprintf("status-%d", s.Code))
}
func (h *handler) ServeHTTP(rw http.ResponseWriter, _ *http.Request) {
_ = json.NewEncoder(rw).Encode(map[string]any{"status": Status{Code: 200}})
}Compiled Go writes {"status":"status-200"}. Yaegi v1 writes {"status":{}}. Yaegi v2 writes the same output as compiled Go.

To do this, Yaegi v2 has its own version of the reflect package, which understands interpreted values. Libraries that use reflect are copied, changed to use this implementation, and compiled into Traefik. 24 libraries are covered today, for example, encoding/json, fmt, text/template, log/slog, yaml, toml, mapstructure, and validator.
We tested 25 common libraries that use reflect: 24 give the same output as go run with Yaegi v2, against one with Yaegi v1.
Many plugin authors want to use the same libraries as in any Go program: gRPC, protobuf, the AWS SDK, OpenTelemetry, the Kubernetes client. These libraries are large, and they use reflect, unsafe, generics, and sometimes assembly. Until now, they were out of reach for plugins.
We wrote 20 test plugins, each built on a library like this, and compared them with a compiled build of the same plugin. Yaegi v2 runs all of them with the same output as the compiled build: protobuf, gRPC, the AWS SDK, OpenTelemetry, the Kubernetes client, the Prometheus client, OPA, a Redis client, zap, and the OpenAI and Anthropic SDKs, among others.
Three things to know:
- Most of these libraries import
unsafeorsyscall. The plugin must setuseUnsafe: truein its manifest, and you must allow it in the plugin settings. - Some libraries import packages that a plugin may not use, like
os/exec, in code that the plugin never runs. Yaegi v2 lets the plugin load and refuses the call if it happens. - A big library means more code to load. The largest plugin of our catalog loads in about 230 ms and keeps about 50 MB of memory.
Faster for Most Plugins
We measured the time per request of three plugins, in µs (lower is better):
| Plugin | Compiled Go | Yaegi v1 | Yaegi v2 |
|---|---|---|---|
| Headers | 1.9 | 11.2 | 4.5 |
| Regexp | 1.16 | 5.5 | 2.9 |
| JSON | 9.6 | 19.7 (wrong output) | 27.8 |

Plugins that work on headers or regular expressions are about two times faster. The JSON plugin is slower, but its output is now correct.
There is one cost. The first load of a plugin in a process takes about 110 ms, compared with 15 ms with Yaegi v1, because the standard library types are decoded once. The next loads take 6 to 24 ms. A loaded plugin uses about 16 MB of memory, and an in-progress request uses about 6 KB, as with Yaegi v1.
Guard Rails for Plugins
A plugin runs inside the Traefik process. So a bug in a plugin can affect the whole proxy. Yaegi v2 adds guardrails:
- An execution budget per call, a goroutine limit, and an approximate memory quota.
os.Exit,log.Fataland panics in plugin goroutines do not stop Traefik.- Each plugin has its own environment, standard streams, and registries, like
http.DefaultServeMux. It cannot assign Traefik variables. - Packages and functions that act on the whole process, like
os/exec, are refused when the plugin loads. - The load checks every function the plugin can reach. Code that Yaegi v2 cannot run fails the load, not a request.
This is not a sandbox. The plugin shares Traefik's memory, so a plugin written to harm Traefik can still do it.
Try Yaegi v2
How to Enable Yaegi v2 in Traefik v3.8
Yaegi plugins run with Yaegi v1 by default. There are two ways to use Yaegi v2.
For all Yaegi plugins, in the static configuration:
experimental:
defaultRuntimeVersion: v2For one plugin, in its manifest (.traefik.yml):
runtimeVersion: v2A plugin that asks for v2 in its manifest always runs with Yaegi v2. The manifest accepts only the value v2, so a plugin cannot ask for Yaegi v1. These options have no effect on Wasm plugins. The plugins documentation has the details.
Two Example Plugins
We published two small plugins that only work with Yaegi v2. You can read them or use them as a starting point for your own plugin. Both have runtimeVersion: v2 in their manifest.
plugin-yaegi-v2-demo removes the request headers that start with a prefix. It is a few lines of code, but it uses an iterator (maps.Keys) and a generic function (slices.ContainsFunc), which Yaegi v1 cannot run:
for name := range maps.Keys(req.Header) {
if slices.ContainsFunc(h.prefixes, func(p string) bool { return strings.HasPrefix(name, p) }) {
req.Header.Del(name)
}
}plugin-markdown-demo renders the Markdown files served by the backend as HTML pages, with syntax highlighting. Put it in front of a file server, and a folder of Markdown files becomes a small documentation site. The plugin itself is short, but it uses goldmark and chroma: about 45,000 lines of Go in its vendor directory, all run by the interpreter. Yaegi v1 cannot load it. With Yaegi v2, it loads in 0.4 s and gives the same HTML as compiled Go. A page takes about 15 ms, against 0.5 ms with compiled Go.

How It Works
Yaegi v2 does not implement the Go language again. It uses the official Go tools for that, and only adds the part that runs the code.

go/parserparses the source.go/typeschecks the types. The types of the standard library are embedded in the binary, so no Go toolchain is needed at runtime.golang.org/x/tools/go/ssabuilds the SSA form. Generic functions are instantiated at this step, so the VM never sees a type parameter.- Each function is compiled to a register bytecode (about 110 opcodes).
- A loop runs the bytecode. Goroutines are Go goroutines, and channels are Go channels.
What this gives:
- The language is the same as Go tools. Yaegi v2 accepts a program when
go buildaccepts it, with the same files and the same build constraints. - Error messages are the Go compiler's.
- A new Go release is mostly new generated data, not new interpreter code.
How We Built It
A Go interpreter has one big advantage for its authors: the expected behavior already exists. For any program, the Go toolchain says what the output must be. So most of our tests run the same program with go and with Yaegi v2, and compare the outputs.
This made Yaegi v2 a good project for AI coding tools. Our engineers made the design choices: the Go tools to understand the code, a bytecode VM to run it, and a second implementation of reflect. Much of the code was then written with AI assistance, and each change was checked against the Go toolchain. The AI writes the code, and the Go toolchain decides if it is correct.
A rewrite of this size was out of reach for a long time. This method made it possible.
Standalone Yaegi v2
Yaegi v2 is also a command-line tool and a Go library:
go install github.com/traefik/yaegi/v2/cmd/yaegi@latest
yaegi hello.goThe module is github.com/traefik/yaegi/v2, on the v2 branch of the repository. The API is not the same as Yaegi v1: the README has a migration table. Yaegi v1 stays on master.
Build the Next Plugins With Us
Traefik plugins exist because of their community: people who had a need, wrote a plugin, and shared it. Yaegi v2 lets this community go much further. The full Go language is available, along with the libraries you already know.
So this is a good time to write the plugin you have in mind. The two example plugins above show how to start, and the Plugin Catalog is the place to share the result.
If you already maintain a plugin, check that go build and go vet pass on it: Yaegi v2 only loads plugins that the Go compiler accepts. Then run it with Yaegi v2 on a test instance and compare with what you have today. If a plugin works with Yaegi v1 and not with Yaegi v2, please open an issue on traefik/yaegi. Each report makes the engine better for every plugin.
Yaegi v2 is available now in Traefik v3.8. Read the plugins documentation to enable it, find or publish plugins in the Plugin Catalog, and follow Yaegi on GitHub.




