Steps
How we tested, and what is real
On 29 October 2026 we ran 13 real executions on a self-hosted n8n 2.43.7 (SQLite, internal JavaScript task runner, Node 24), each a Manual Trigger followed by one test node. n8n was started with
MY_KEY=secret123in its environment, and a local server echoed back the URL the HTTP Request node called. Every error text below is what n8n really printed.The error: blocked by default in n8n 2.x
With
N8N_BLOCK_ENV_ACCESS_IN_NODEnot set at all, every read of$envfailed withaccess to env vars denied. Setting it totruegave the same result: in n8n 2.x, blocked is the default. If your workflow used$envon 1.x and broke after the update, this is why.Same message, three different error types
The text is the same everywhere, but where it shows up differs. In a Code node (
$env.MY_KEY) it was a WrappedExecutionError from the task runner. In Edit Fields (Set) with{{ $env.MY_KEY }}it was a NodeOperationError. In an HTTP Request URL with{{ $env.MY_KEY }}it was an ExpressionError, raised while n8n filled in the parameters, before any request went out. Writing$env.NOT_SET_VAR ?? 'default'did not help: n8n blocks the read before it looks at the value.The fix: N8N_BLOCK_ENV_ACCESS_IN_NODE=false, then restart
With
N8N_BLOCK_ENV_ACCESS_IN_NODE=falseall three nodes worked: the Code node and Edit Fields returnedsecret123, and the HTTP Request called/?k=secret123. In docker-compose, add- N8N_BLOCK_ENV_ACCESS_IN_NODE=falseunderenvironment:and recreate the container (docker compose up -d); a plain restart does not reload a changed compose file. In queue mode or with external task runners, set it where the workflow actually runs too (we did not test that). Know the trade-off: anyone who can edit a workflow can then read every environment variable of n8n, includingN8N_ENCRYPTION_KEYand database passwords.After unblocking: silent undefined
Once access was allowed,
$env.NOT_SET_VARreturnedundefinedwith no error at all. So a typo in the name, or a variable that is only in your shell or in a .env file that the container never loaded, gives an empty value instead of a clear error. Check what n8n itself sees withdocker exec -it n8n env(use your container name).process.env does not work in the Code node
process.env.MY_KEYfailed withprocess is not defined [line 1]in every mode, even with access unblocked. The Code node runs in a sandbox withoutprocess. Use$env.MY_KEYinstead.$vars is not $env
{{ $vars.MY_KEY }}reads n8n Variables (a paid feature set in the n8n UI), not environment variables. On our unlicensed instance it returnednullwith no error. If a value comes back empty, check you wrote$env.Safer than unblocking
For API keys, a credential is the better place: it is encrypted, and only that node sees it. For a plain constant (a base URL, a sheet ID), put it in an Edit Fields node at the start of the workflow and read it with
{{ $('Config').item.json.baseUrl }}. That keepsN8N_BLOCK_ENV_ACCESS_IN_NODEat its safe default.
All test results
13 real executions. Left: what we ran. Right: what n8n 2.43.7 did (all real).
| Test | Result |
|---|---|
| Code node $env.MY_KEY, default (not set) | access to env vars denied (WrappedExecutionError) |
| Code node $env.NOT_SET_VAR ?? default, default | access to env vars denied: ?? does not help |
| Edit Fields {{ $env.MY_KEY }}, default | access to env vars denied (NodeOperationError) |
| HTTP Request URL with {{ $env.MY_KEY }}, default | access to env vars denied (ExpressionError), no request sent |
| Code node, N8N_BLOCK_ENV_ACCESS_IN_NODE=true | Same error as default |
| Code node, =false | Works: secret123 |
| Edit Fields, =false | Works: secret123 |
| HTTP Request URL, =false | Works: called /?k=secret123 |
| Code node $env.NOT_SET_VAR, =false | undefined, no error |
| Code node, MY_KEY set to empty, =false | Empty value, no error |
| Code node process.env.MY_KEY, default | process is not defined [line 1] |
| Code node process.env.MY_KEY, =false | process is not defined [line 1] |
| Edit Fields {{ $vars.MY_KEY }}, unlicensed | null, no error |
Checklist
- Seeing access to env vars denied on n8n 2.x? Env access is blocked by default.
- Need it: set
N8N_BLOCK_ENV_ACCESS_IN_NODE=falsein n8n's own environment and recreate the container. - Value empty after that? The variable is not in n8n's process: check with
docker exec ... env, and check the spelling. - Code node:
$env.X, neverprocess.env.X. $varsis n8n Variables, not environment variables.- Secrets belong in credentials; constants can live in an Edit Fields node.
Good to know
- Other things that break when moving from 1.x to 2.x: n8n upgrade and migration errors.
- Other Code node errors: n8n Code node errors. Expressions returning undefined: n8n expression errors. HTTP Request problems: n8n HTTP Request node errors.
- Every error text from our n8n guides is in the n8n error message index.
What we did not test
Docker compose env_file loading, n8n Cloud (env access stays blocked there), queue mode workers and external task runners, the Python Code node, and $env inside credential fields.
Start from a working agent
FAQ
What does "access to env vars denied" mean in n8n?
n8n blocked a read of $env. Since n8n 2.x this is the default; set N8N_BLOCK_ENV_ACCESS_IN_NODE=false in n8n's environment and restart to allow it.
How do I use environment variables in an n8n Code node?
Use $env.MY_VAR after setting N8N_BLOCK_ENV_ACCESS_IN_NODE=false. process.env does not exist in the Code node sandbox and fails with process is not defined.
Why is $env empty in n8n?
After unblocking, a variable n8n's own process does not have returns undefined with no error. Make sure it is passed into the container and spelled the same.
Is it safe to set N8N_BLOCK_ENV_ACCESS_IN_NODE=false?
It lets anyone who can edit workflows read every environment variable, including the encryption key. Prefer credentials for secrets.
What is the difference between $vars and $env in n8n?
$env reads environment variables; $vars reads n8n Variables, a paid feature. On an unlicensed instance $vars returned null without an error.
Related guides
- n8n broke after updating to 2.x? Upgrade and migration errors, 20 tests
- n8n Python Code node not working? Task runner errors, 9 tests
- n8n Execute Command and Read/Write Files errors: 61 real runs, fixed
- n8n binary data not found? Fix 'none was found' and 'no binary field', 25 tests
- n8n Airtable node not working: Unauthorized, NOT_FOUND and Base ID fixes
New guides
- GitHub release notifications in Slack (any public repo, stable releases only)
- Send RSS feeds to Slack with a keyword filter (free, incoming webhook)
- Forward emails to a Slack channel (Gmail, Outlook, any IMAP), free with an incoming webhook
- n8n Google Sheets Trigger not working: not firing, activation errors and fixes