Code Node Sandbox Reference

What you can and cannot do in Code Nodes — constraints, available variables, and performance tips.

Written By pvdyck

Last updated About 5 hours ago

Code Node Sandbox Reference

Code Nodes run in a secure, isolated sandbox. This page explains what is available and what constraints apply.

Constraint Table

FeatureAvailable?Note
async/awaitNoCode must be synchronous
fetch / XMLHttpRequestNoNo network access from Code Node
require / importNoNo module system
console.logNoLogs discarded; use return values
setTimeout / setIntervalNoNo timers
File system (fs)NoNo file access
Math, Date, JSONYesFull standard library
Array, Object, String, RegExpYesFull standard library
PromisesLimitedCan create Promises but cannot await them
GeneratorsYesSynchronous generators work
ES2020 syntaxYesArrow functions, destructuring, spread, etc.

CPU Time Limit

Each Code Node execution has a 2-minute CPU time limit. This counts actual CPU computation, not wall-clock time. Infinite loops will be terminated.

Performance Tips

The sandbox engine is optimized for lightweight logic. Complex string manipulation or large array operations may be noticeably slower than in a browser. Keep Code Node logic lean — offload complex processing to upstream HTTP Request nodes where possible.

Available n8n Variables

  • $input — input items (.all(), .first(), .last(), .item(), .context, .params)
  • $json — shortcut to first item's JSON
  • $('NodeName') — access other nodes (.first(), .last(), .all(), .item(), .json, .context, .params)
  • $node['Name'] — proxy-based node accessor (.json, .binary, .context, .parameter, .runIndex)
  • $item(n) — access item by index
  • $items() — all items as INodeExecutionData[]
  • $prevNode — previous node info (name, outputIndex, runIndex)
  • $workflow — workflow metadata (id, name, active)
  • $env — environment variables
  • $vars — workflow variables
  • $execution — execution metadata
  • $mode — execution mode
  • $now, $today, $yesterday — Luxon-like dates (.toISO(), .toFormat(), .plus(), .minus())
  • DateTime — date factory (.now(), .fromISO(), .fromJSDate())
  • $nodeVersion, $nodeId — node metadata
  • $itemIndex, $runIndex — current indices
  • $getNodeParameter — access node parameters

Related