n8n expression engine: vm, quickjs and legacy explained
How n8n's expression engine works: N8N_EXPRESSION_ENGINE values, the 5-second timeout and memory limit, the editor engine, and why to avoid legacy.

n8n's expression engine is the part of n8n that evaluates every {{ }} expression in your workflows. Since n8n 2.35.0 the server uses the vm engine by default, which runs each expression in a sandboxed V8 isolate with a 5-second timeout and a 128 MiB memory limit. You choose the engine with N8N_EXPRESSION_ENGINE (vm, quickjs or legacy). The editor in your browser has its own setting, N8N_EXPRESSION_ENGINE_FRONTEND, which still defaults to legacy.
We checked the defaults, the timeout and the legacy switch on n8n 2.50.0 in Docker on November 26, 2026.
The short version
- Backend default:
vmfrom n8n 2.35.0,legacybefore that. - Limits: each evaluation stops after
N8N_EXPRESSION_ENGINE_TIMEOUT(5000 ms) and each sandbox getsN8N_EXPRESSION_ENGINE_MEMORY_LIMIT(128 MiB). An endless loop fails the node withExpression timed outinstead of hanging the instance. - Editor:
N8N_EXPRESSION_ENGINE_FRONTENDislegacyby default; n8n's docs strongly recommend setting it toquickjs(available from 2.41.0). legacyruns expressions without isolation. n8n 2.50 logs at startup that it "is no longer considered secure, and will be removed in a future version." Use it only as a short-term workaround.- Install problem: if n8n says it
Could not initialize the vm expression engine, the nativeisolated-vmmodule didn't build or load. The Docker image avoids this.
What the expression engine does
Expressions are the JavaScript snippets n8n evaluates at runtime to set node parameters dynamically, such as {{ $json.email }} or {{ $now.toISO() }} (our expressions cheat sheet lists the common ones). n8n evaluates them in two places, and each has its own engine (expression engine docs):
- Backend: the n8n server evaluates expressions when a workflow runs.
N8N_EXPRESSION_ENGINEselects this engine. - Editor: your browser evaluates expressions while you build, for example to preview a result.
N8N_EXPRESSION_ENGINE_FRONTENDselects this engine.
The two settings are independent. This is separate from the Code node, which runs on task runners.
The three engines
| Engine | Where it runs | Status |
|---|---|---|
vm | A sandboxed V8 isolate (the isolated-vm module) | Backend default from 2.35.0 |
quickjs | A QuickJS sandbox compiled to WebAssembly | Available for the backend and the editor; the 2.50.0 source comments call the backend option "Experimental" |
legacy | In the n8n process, without isolation | Editor default; backend default before 2.35.0; n8n plans to remove it |
Why it matters: an expression can be written by anyone who can edit a workflow. With legacy, that code runs inside the n8n process itself, so n8n's docs warn it "gives less protection against malicious expressions than the sandboxed engines." The sandboxed engines also put a ceiling on runaway expressions.
The editor can't use vm, because isolated-vm is a native Node.js module. In the 2.50.0 source, N8N_EXPRESSION_ENGINE_FRONTEND=vm is rejected with a warning and falls back to legacy.
The settings
From n8n's expression engine variables page and the 2.50.0 config:
| Variable | Default | What it does |
|---|---|---|
N8N_EXPRESSION_ENGINE | vm | Backend engine: vm, quickjs or legacy |
N8N_EXPRESSION_ENGINE_FRONTEND | legacy | Editor engine: legacy or quickjs (from 2.41.0) |
N8N_EXPRESSION_ENGINE_TIMEOUT | 5000 | Milliseconds per evaluation. Must be a positive whole number |
N8N_EXPRESSION_ENGINE_MEMORY_LIMIT | 128 | MiB per sandbox. Must be a whole number of at least 8 |
N8N_EXPRESSION_ENGINE_POOL_SIZE | 1 | Sandboxes kept warm in the pool |
N8N_EXPRESSION_ENGINE_MAX_CODE_CACHE_SIZE | 1024 | Compiled expressions kept in the cache |
N8N_EXPRESSION_ENGINE_IDLE_TIMEOUT | Not set | If set, scales the pool to zero warm sandboxes after this many idle seconds |
The pool, timeout and memory settings only apply to vm and quickjs; they do nothing with legacy. An invalid value doesn't stop n8n: the 2.50.0 config tests show it logs a warning and falls back to the default (for example N8N_EXPRESSION_ENGINE=not-an-engine becomes vm, and a timeout of 0 or 2.5 becomes 5000).
In Docker Compose:
services:
n8n:
environment:
- N8N_EXPRESSION_ENGINE=vm
- N8N_EXPRESSION_ENGINE_FRONTEND=quickjs
- N8N_EXPRESSION_ENGINE_TIMEOUT=5000Our n8n environment variables guide covers the other production settings.
What happens when an expression runs too long
We ran an Edit Fields (Set) node with two fields on n8n 2.50.0 with default settings: one with {{ [1,2,3].map(n => n * 2).join(',') }}, and one with an endless loop, {{ (() => { while (true) {} })() }}.
- Default settings: the node failed after 5,079 ms with
Expression timed out, and the instance kept running. N8N_EXPRESSION_ENGINE_TIMEOUT=1000: the same node failed after 1,078 ms with the same message.
So if a node that used to work starts failing with Expression timed out after you upgrade past 2.35, look for an expression that does heavy work in a loop over many items, and move that work to a Code node, which has its own limits on task runners. Raise the timeout only if the expression really needs longer.
The changelog shows n8n still smoothing out differences between the engines in recent releases. 2.50.0, for example, lists fixes so multi-line string values stay unchanged, an item holding a value the vm engine can't copy is still returned, and an expression that reaches the memory limit on quickjs throws. If an expression behaves differently after an upgrade, check the changelog for your version first.
Switching back to legacy (only as a workaround)
If an expression breaks under vm and you need your workflows running today, you can switch the backend back:
services:
n8n:
environment:
- N8N_EXPRESSION_ENGINE=legacyOn 2.50.0 our test workflow ran normally with legacy, and n8n printed this in its startup deprecation list:
N8N_EXPRESSION_ENGINE -> The `legacy` expression engine runs expressions without isolation, is no longer considered secure, and will be removed in a future version. Remove this environment variable to use the default `vm` engine.Treat it as temporary: note which expression needed it, fix that expression or move the logic to a Code node, then remove the variable. With legacy, the timeout and memory limit don't apply, so nothing caps a runaway expression.
"Could not initialize the vm expression engine"
The vm engine depends on isolated-vm, a native module that has to be compiled for the exact Node.js version that runs n8n. When it can't load, n8n refuses to start. We hit this when we installed n8n 2.49.5 with npm under one Node.js version and started it under another:
IsolatePool failed to create any bridges
Error: Could not initialize the vm expression engine (see errors above for details). If they point at isolated-vm, check that it installed correctly, e.g. that native build scripts were not skipped.The fix is to run n8n where isolated-vm was built for it: reinstall n8n with the Node.js version you run it with (and without skipping install scripts), or use the official Docker image, which started cleanly in the same test. n8n 3.0 drops npm installs anyway, so our guide to moving n8n from npm to Docker is worth reading if you're still on npm.
Tracing slow expressions
With vm or quickjs, n8n can send an OpenTelemetry span for each expression that fails, takes longer than N8N_EXPRESSION_ENGINE_SLOW_EVAL_THRESHOLD_MS (50 ms by default) or falls in the sample. Turn it on with N8N_EXPRESSION_ENGINE_TRACES_ENABLED=true (the default is false from n8n 2.45.0) together with OpenTelemetry itself (N8N_OTEL_ENABLED). legacy never emits these spans. Our monitoring guide covers metrics and alerts for the rest of the instance.
Next steps
- n8n expressions cheat sheet: the expressions themselves, and their common errors.
- n8n task runners explained: how the Code node is isolated, the other half of running user code safely.
- More on working with data in n8n: the expressions tag.
Sources
Editorial team
The then8nblog editorial team researches every article from n8n's release notes, documentation and source code, states the n8n version each guide was tested on, and has every post reviewed by a human editor before it goes live.



