Setup help

n8n env access denied

If one of these flows stops while reading $env, this is the usual cause. n8n 2.x blocks environment variables inside expressions and Code nodes unless you allow them.

The flow file and setup help are in #freebies on our Discord.

What changed in n8n 2.x

n8n 2.x sets N8N_BLOCK_ENV_ACCESS_IN_NODE to true by default. A node that reads $env.ANTHROPIC_API_KEY, or any other $env name, is denied. The workflow still imports. It fails when that node runs.

On a server you host, you can allow $env or use a credential. n8n Cloud cannot set custom environment variables, so there you use a credential, or $vars on plans that support them.

On a server you host

Allow $env

Set N8N_BLOCK_ENV_ACCESS_IN_NODE=false in the environment that starts n8n. That might be a Docker Compose file, a systemd unit, or the host environment. Restart n8n after the change. Expressions and Code nodes can read $env again. Also set the keys the flow names, such as ANTHROPIC_API_KEY.

Or use a credential

Leave the block on. In n8n, create a credential for the secret. Header Auth is the usual one for an API key. Open the HTTP node, choose that credential, and remove the $env expression from the header. The value stays in n8n. It is not written into the workflow file you imported.

On n8n Cloud

n8n Cloud cannot set custom environment variables, so N8N_BLOCK_ENV_ACCESS_IN_NODE is not a switch you can flip there. Use a credential instead of $env. Create it, attach it to the node that needs the key, and clear the $env expression.

On plans that support custom variables, you can use $vars instead of $env. Put the secret in a variable and read $vars.NAME in the node. That stays inside n8n Cloud. It is not an instance environment variable.

Free flows that read $env

These flows read $env for at least one secret. The others keep keys in placeholders or n8n credentials.

Questions

Why did a flow that used to run start failing?

n8n 2.x turns on N8N_BLOCK_ENV_ACCESS_IN_NODE. Nodes that read $env are denied until you set that variable to false or move the secret into a credential.

Is the API key inside the flow file?

No. The file contains a name such as $env.ANTHROPIC_API_KEY. The value lives in your n8n environment, or in a credential you attach after import.

Which fix should I use?

On a server you host, either set N8N_BLOCK_ENV_ACCESS_IN_NODE=false and restart, or use credentials. On n8n Cloud, use a credential, or $vars custom variables on plans that support them. Cloud cannot set custom environment variables.

Does this change the workflow JSON?

No. You change the n8n instance, or you attach a credential on the node after import. The flow file stays the same.

A small note

Goat O Mate is a community of builders shipping marketing and AI automations together.

Join Discord