> For the complete documentation index, see [llms.txt](https://docs.n8n.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.n8n.io/deploy/host-n8n/configure-n8n/basic-configuration/use-environment-variables/expression-engine.md). Agents can also search and read this documentation through its [MCP server](https://docs.n8n.io/~gitbook/mcp).

# Expression engine

Choose the expression engines for the n8n backend and editor, and configure native evaluation and the sandbox for your self-hosted n8n instance.

{% hint style="info" %}
**File-based configuration**

You can add `_FILE` to individual variables to provide their configuration in a separate file. Refer to [Keeping sensitive data in separate files](https://docs.n8n.io/deploy/host-n8n/configure-n8n/basic-configuration.md#keeping-sensitive-data-in-separate-files) for more details.
{% endhint %}

[Expressions](https://docs.n8n.io/build/work-with-data/expressions-versus-data-nodes.md) are the JavaScript snippets n8n evaluates at runtime to set node parameters dynamically. The expression engine is the component that runs that evaluation. This page lists environment variables for configuring it. To learn how the engines work, how they differ, and how to move away from `legacy`, refer to [Expression engines](https://docs.n8n.io/deploy/host-n8n/configure-n8n/expression-engines.md).

n8n reads these variables at startup. Restart n8n after you change one. In [queue mode](https://docs.n8n.io/deploy/host-n8n/configure-n8n/scaling/enable-queue-mode.md), set the same values on main, worker, and webhook processes.

{% hint style="warning" %}
**Avoid the `legacy` expression engine**

The `legacy` engine runs expressions without isolation, so it gives less protection against malicious expressions than the sandboxed engines. The `legacy` engine is deprecated: n8n logs a deprecation warning at startup when the backend uses it, and plans to remove it in a future version. For the strongest security posture:

* Keep `N8N_EXPRESSION_ENGINE` set to `vm`, the backend default.
* Set `N8N_EXPRESSION_ENGINE_FRONTEND` to `quickjs`. The editor still uses `legacy` by default.
  {% endhint %}

## Choose the expression engine

n8n evaluates expressions in two places, and each has its own engine setting:

* **Backend:** the n8n server evaluates expressions when a workflow runs. `N8N_EXPRESSION_ENGINE` selects this engine.
* **Editor:** your browser evaluates expressions while you build a workflow, for example to preview an expression's result. `N8N_EXPRESSION_ENGINE_FRONTEND` selects this engine.

The two settings are independent.

| Variable                         | Type                                   | Default  | Description                                                                                                                                                                                                                                                                                                                                                                      |
| -------------------------------- | -------------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `N8N_EXPRESSION_ENGINE`          | Enum string: `vm`, `quickjs`, `legacy` | `vm`     | Which expression engine the backend uses. `vm` runs expressions in a sandboxed V8 isolate. `quickjs` runs them in a QuickJS sandbox compiled to WebAssembly. n8n doesn't support `quickjs` on the backend. `legacy` runs them without isolation, and is deprecated. `vm` is the default from n8n 2.35.0, and from n8n 1.123.73 on 1.x. Earlier n8n versions default to `legacy`. |
| `N8N_EXPRESSION_ENGINE_FRONTEND` | Enum string: `legacy`, `quickjs`       | `legacy` | Which expression engine the editor uses in the browser. `quickjs` runs expressions in a QuickJS sandbox compiled to WebAssembly, isolated from the rest of the page. `legacy` runs them without isolation. n8n strongly recommends `quickjs`. Available from n8n 2.41.0.                                                                                                         |

The `quickjs` engine in the editor needs WebAssembly. If you set your own `N8N_CONTENT_SECURITY_POLICY`, its `script-src` directive, or `default-src` when there's no `script-src`, must allow WebAssembly with `'wasm-unsafe-eval'` or `'unsafe-eval'`. Refer to [Use the quickjs engine in the editor](https://docs.n8n.io/deploy/host-n8n/configure-n8n/expression-engines.md#use-the-quickjs-engine-in-the-editor).

## Evaluate simple expressions natively

n8n can evaluate simple expressions directly, without a sandbox. n8n does this only for expressions that use a fixed set of operations, such as reading a field with `{{ $json.email }}` or comparing two values. The configured engine evaluates every other expression. Refer to [Evaluate simple expressions without a sandbox](https://docs.n8n.io/deploy/host-n8n/configure-n8n/expression-engines.md#evaluate-simple-expressions-without-a-sandbox) for the full list.

| Variable                                                | Type    | Default | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ------------------------------------------------------- | ------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `N8N_EXPRESSION_ENGINE_NATIVE_EVALUATION`               | Boolean | `false` | Whether n8n evaluates simple expressions directly instead of sending them to the expression engine. Applies to every backend engine, including `legacy`. Available from n8n 2.43.0.                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `N8N_EXPRESSION_ENGINE_NATIVE_EVALUATION_VERIFY_SAMPLE` | Number  | `0`     | Share of simple expressions, from `0` to `1`, that n8n evaluates both natively and with the engine to compare the results. n8n always uses the engine's result and reports differences to Sentry. Each n8n process reports each difference once, up to 1000 differences. A difference is the masked expression, the engine, and the type of each result. The report contains a masked form of the expression and the workflow ID, but no workflow data. Doesn't work with the `legacy` engine. Only works when you set `N8N_SENTRY_DSN` and leave `N8N_EXPRESSION_ENGINE_NATIVE_EVALUATION` at `false`. Available from n8n 2.46.0. |

## Configure the sandboxed backend engines

These variables configure the backend `vm` and `quickjs` engines. They have no effect when `N8N_EXPRESSION_ENGINE` is `legacy`, and they don't affect the editor's engine. The editor's `quickjs` engine always uses a 5000 millisecond timeout and a 128 MiB memory limit.

| Variable                                    | Type    | Default | Description                                                                                                                                                                                                                                          |
| ------------------------------------------- | ------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `N8N_EXPRESSION_ENGINE_LAZY_ACQUIRE`        | Boolean | `false` | Whether n8n creates a sandbox only when an expression needs the engine. When `false`, n8n usually takes a sandbox when an execution, trigger, or webhook request starts, before it knows whether an expression needs one. Available from n8n 2.40.0. |
| `N8N_EXPRESSION_ENGINE_COMPILE_CACHE`       | Boolean | `false` | Whether n8n reuses V8's compile cache when it creates a sandbox, which makes creation faster. Only affects the `vm` engine. Available from n8n 2.40.0.                                                                                               |
| `N8N_EXPRESSION_ENGINE_POOL_SIZE`           | Number  | `1`     | Number of sandboxes kept warm in the pool. The pool absorbs short bursts. It doesn't limit how many sandboxes can exist at the same time.                                                                                                            |
| `N8N_EXPRESSION_ENGINE_MAX_CODE_CACHE_SIZE` | Number  | `1024`  | Maximum number of compiled expressions to cache.                                                                                                                                                                                                     |
| `N8N_EXPRESSION_ENGINE_TIMEOUT`             | Number  | `5000`  | Execution timeout in milliseconds for each expression evaluation. Must be a positive integer. An expression that takes longer fails with `Expression timed out`.                                                                                     |
| `N8N_EXPRESSION_ENGINE_MEMORY_LIMIT`        | Number  | `128`   | Memory limit in MiB for each sandbox. Must be an integer of at least `8`. An expression that needs more fails with `Expression exceeded memory limit`. On `vm`, later expressions in the same execution that need the engine also fail.              |
| `N8N_EXPRESSION_ENGINE_IDLE_TIMEOUT`        | Number  | -       | If set, scales the pool to zero warm sandboxes after this many seconds with no activity.                                                                                                                                                             |

## Trace expression evaluations

These variables control the `expression.evaluate` OpenTelemetry spans. Like the variables above, they only work with the `vm` and `quickjs` backend engines. The spans also need OpenTelemetry turned on, with `N8N_OTEL_ENABLED` or **Enable OpenTelemetry** in **Settings > OpenTelemetry**. Refer to [Choose which spans n8n exports](https://docs.n8n.io/deploy/host-n8n/keep-n8n-running/trace-executions-with-opentelemetry/choose-which-spans-n8n-exports.md#trace-expression-evaluations).

| Variable                                       | Type    | Default | Description                                                                                                                                                                                                                               |
| ---------------------------------------------- | ------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `N8N_EXPRESSION_ENGINE_TRACES_ENABLED`         | Boolean | `false` | Whether n8n sends an `expression.evaluate` span for expressions that fail, take longer than the slow threshold, or fall in the sample. Available from n8n 2.19.0. The default is `false` from n8n 2.45.0, and `true` in earlier versions. |
| `N8N_EXPRESSION_ENGINE_SLOW_EVAL_THRESHOLD_MS` | Number  | `50`    | Duration in milliseconds above which n8n treats an evaluation as slow and always sends its span.                                                                                                                                          |
| `N8N_EXPRESSION_ENGINE_TRACES_SAMPLE_RATE`     | Number  | `0`     | Fraction of healthy evaluations to send spans for, from `0` to `1`. Failing and slow evaluations always get a span.                                                                                                                       |
| `N8N_EXPRESSION_ENGINE_OBSERVABILITY_ENABLED`  | Boolean | `true`  | Whether the backend engine emits observability signals for expression evaluation: metrics, traces, and logs. Set to `false` to turn them all off, including expression spans, whatever the other settings say.                            |

Expressions that n8n evaluates natively don't create a span.

## Related resources

* [Expression engines](https://docs.n8n.io/deploy/host-n8n/configure-n8n/expression-engines.md)
* [Environment variables](https://docs.n8n.io/deploy/host-n8n/configure-n8n/basic-configuration/use-environment-variables.md)
* [OpenTelemetry environment variables](https://docs.n8n.io/deploy/host-n8n/configure-n8n/basic-configuration/use-environment-variables/opentelemetry.md)
