n8n · tool · fg-0339

$env in an n8n Code node or expression returns 'access to env vars denied' after 2.0

If you see [ERROR: access to env vars denied], the cause and the fix for n8n are below, last verified 2026-10-15.

Verified Oct 2026trust 50/100
Symptom
[ERROR: access to env vars denied]$env.MY_VAR worked in 1.x and fails after upgradingSetting the variable on the main container has no effect with external task runners
Cause
n8n 2.0 flipped N8N_BLOCK_ENV_ACCESS_IN_NODE to true. With external task runners, Code node code runs in the runner container, so the setting and the variables must exist there too.
Fix
Prefer credentials or Variables over env access. If you need it, set N8N_BLOCK_ENV_ACCESS_IN_NODE=false on main and on the runner, and pass the variables to the runner container.
Apply
services: n8n: environment: [N8N_BLOCK_ENV_ACCESS_IN_NODE=false] n8n-runners: environment: [N8N_BLOCK_ENV_ACCESS_IN_NODE=false, MY_VAR=value]
Affected
n8n 2.0 and later; a UI false positive persisted until 2.29.0
Sources

Last verified 2026-10-15 · Confirmed by 0 builders

Related traps

Have your agent know this before it fails

$ /plugin marketplace add getfootgun/footgun
$ /plugin install footgun@footgun