GuidesNodes
Code
Run JavaScript in an isolated sandbox to transform, compute, or reshape data.
Code nodes execute user-provided JavaScript in an isolated sandbox. Use them to parse, transform, filter, or compute values from upstream data before passing results to LLM, HTTP, Decision, or other downstream nodes.
Configuration
| Field | Type | Required | Description |
|---|---|---|---|
| code | string | No | JavaScript source code to execute. The script receives the trigger payload and upstream outputs as an input object and must return a value that becomes the node's output. |
Input
The node receives the trigger payload and upstream node outputs as a single input object. Your code can read any property from this object:
// Access trigger payload fields
const text = input.text;
// Access upstream node output
const items = input.items;
// Return a transformed value
return items.filter(item => item.score > 0.5);Output
The return value of the script becomes the node's output. It is stored in the node execution record and passed to all downstream nodes. If the script throws an error, the node fails and the error message is recorded.
Execution sandbox
Code nodes run in an isolated JavaScript sandbox:
- No access to the host filesystem, network, or process environment.
- No access to global state shared with other nodes or graphs.
- Execution time and memory are bounded by platform limits. Keep scripts focused and avoid heavy computation.
- The code is stored as part of the graph definition and versioned alongside the graph.
Tips
- Use code nodes for deterministic transformations: normalizing data, filtering arrays, formatting strings, building prompt templates, or computing values for Switch nodes.
- Always return a consistent shape so downstream nodes can rely on the structure of the output.
- Validate and sanitize inputs to prevent runtime errors from unexpected data.
- Keep scripts short and readable. For complex logic, split work across multiple code nodes to keep each step testable and maintainable.