Automations

Code (JS Sandbox) Node

6 min readnode-data-code

Run arbitrary JavaScript inside a sandboxed V8 context — transform data, call external APIs, parse JSON, compute values — all from within an automation.

Code (JS Sandbox) Node

The Code node executes a JavaScript snippet in a sandboxed V8 context. Use it to transform variables, compute derived values, parse JSON from an LLM, or call external APIs that don't have a dedicated node.

> Note: The sandbox has no file system access, no require, and no network access. Use the Webhook node to call external APIs instead, or use fetch which is available inside the sandbox.

---

Fields
FieldTypeRequiredDescription
codestringYesJavaScript to execute. Must return a value or call setOutput(key, value)
outputVarstringNoVariable name to store the return value (default: codeOutput)

---

Context available inside the sandbox
NameTypeDescription
variablesobjectAll current flow variables (read-only)
leadobjectThe trigger lead object (read-only)
flowStateobjectThe current $flow.state object
fetchfunctionStandard fetch API for HTTP requests
setOutputfunctionsetOutput(key, value) — set multiple output variables

---

Example: parse JSON from an LLM response

js // variables.llmResponse = '{"score": 8, "reason": "Strong fit"}' const parsed = JSON.parse(variables.llmResponse); setOutput('score', parsed.score); setOutput('reason', parsed.reason); return parsed;

---

Example: format a phone number

js const raw = lead.phone || ''; const digits = raw.replace(/\D/g, ''); return digits.startsWith('44') ? '+' + digits : '+44' + digits;

---

Example: call an external API

js const res = await fetch('https://api.example.com/score', { method: 'POST', headers: { 'Authorization': 'Bearer ' + variables.apiKey, 'Content-Type': 'application/json' }, body: JSON.stringify({ domain: lead.domain }) }); const data = await res.json(); return data.score;

---

Execution limits
LimitValue
Max execution time10 seconds
Max output size100 KB
Memory64 MB
Network requestsAllowed (via fetch)

---

Tips
  • Always return something — if the node returns undefined, outputVar is set to null
  • Wrap risky code in try/catch and return a fallback value so the automation doesn't halt
  • Use setOutput when you want to set multiple variables from one code node instead of chaining multiple set_variable nodes