Code (JS Sandbox) Node
Run arbitrary JavaScript inside a sandboxed V8 context — transform data, call external APIs, parse JSON, compute values — all from within an automation.
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.
---
| Field | Type | Required | Description |
|---|---|---|---|
code | string | Yes | JavaScript to execute. Must return a value or call setOutput(key, value) |
outputVar | string | No | Variable name to store the return value (default: codeOutput) |
---
| Name | Type | Description |
|---|---|---|
variables | object | All current flow variables (read-only) |
lead | object | The trigger lead object (read-only) |
flowState | object | The current $flow.state object |
fetch | function | Standard fetch API for HTTP requests |
setOutput | function | setOutput(key, value) — set multiple output variables |
---
js
// variables.llmResponse = '{"score": 8, "reason": "Strong fit"}'
const parsed = JSON.parse(variables.llmResponse);
setOutput('score', parsed.score);
setOutput('reason', parsed.reason);
return parsed;
---
js
const raw = lead.phone || '';
const digits = raw.replace(/\D/g, '');
return digits.startsWith('44') ? '+' + digits : '+44' + digits;
---
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;
---
| Limit | Value |
|---|---|
| Max execution time | 10 seconds |
| Max output size | 100 KB |
| Memory | 64 MB |
| Network requests | Allowed (via fetch) |
---
- Always
returnsomething — if the node returnsundefined,outputVaris set tonull - Wrap risky code in try/catch and return a fallback value so the automation doesn't halt
- Use
setOutputwhen you want to set multiple variables from one code node instead of chaining multipleset_variablenodes