// guides · n8n error index

n8n 'access to env vars denied'? 13 tests and the fix

Fix n8n access to env vars denied in Code, Set and HTTP Request nodes: N8N_BLOCK_ENV_ACCESS_IN_NODE, process is not defined, $vars null. 13 real runs.

Updated 2026-10-29 · about 10 minutes

Still stuck after these steps? Paste your exact n8n error and we'll reproduce it and email you the fix, free →

Steps

  1. 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=secret123 in its environment, and a local server echoed back the URL the HTTP Request node called. Every error text below is what n8n really printed.

  2. The error: blocked by default in n8n 2.x

    With N8N_BLOCK_ENV_ACCESS_IN_NODE not set at all, every read of $env failed with access to env vars denied. Setting it to true gave the same result: in n8n 2.x, blocked is the default. If your workflow used $env on 1.x and broke after the update, this is why.

  3. 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.

  4. The fix: N8N_BLOCK_ENV_ACCESS_IN_NODE=false, then restart

    With N8N_BLOCK_ENV_ACCESS_IN_NODE=false all three nodes worked: the Code node and Edit Fields returned secret123, and the HTTP Request called /?k=secret123. In docker-compose, add - N8N_BLOCK_ENV_ACCESS_IN_NODE=false under environment: 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, including N8N_ENCRYPTION_KEY and database passwords.

  5. After unblocking: silent undefined

    Once access was allowed, $env.NOT_SET_VAR returned undefined with 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 with docker exec -it n8n env (use your container name).

  6. process.env does not work in the Code node

    process.env.MY_KEY failed with process is not defined [line 1] in every mode, even with access unblocked. The Code node runs in a sandbox without process. Use $env.MY_KEY instead.

  7. $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 returned null with no error. If a value comes back empty, check you wrote $env.

  8. 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 keeps N8N_BLOCK_ENV_ACCESS_IN_NODE at its safe default.

All test results

13 real executions. Left: what we ran. Right: what n8n 2.43.7 did (all real).

TestResult
Code node $env.MY_KEY, default (not set)access to env vars denied (WrappedExecutionError)
Code node $env.NOT_SET_VAR ?? default, defaultaccess to env vars denied: ?? does not help
Edit Fields {{ $env.MY_KEY }}, defaultaccess to env vars denied (NodeOperationError)
HTTP Request URL with {{ $env.MY_KEY }}, defaultaccess to env vars denied (ExpressionError), no request sent
Code node, N8N_BLOCK_ENV_ACCESS_IN_NODE=trueSame error as default
Code node, =falseWorks: secret123
Edit Fields, =falseWorks: secret123
HTTP Request URL, =falseWorks: called /?k=secret123
Code node $env.NOT_SET_VAR, =falseundefined, no error
Code node, MY_KEY set to empty, =falseEmpty value, no error
Code node process.env.MY_KEY, defaultprocess is not defined [line 1]
Code node process.env.MY_KEY, =falseprocess is not defined [line 1]
Edit Fields {{ $vars.MY_KEY }}, unlicensednull, no error

Checklist

Good to know

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.

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

New guides

Still stuck on your n8n error?

Paste the exact error and say what the workflow should do. We reproduce it on a real n8n install and email you the fix or a working workflow, usually within 24h. Free while we're in beta.

We'll only email you about your error and TaskToAgent.