Skip to main content

Code Node - Custom JavaScript Execution in ConvyAI Agentic Flow

Overview​

The Code node executes a custom JavaScript snippet within the flow. The script can read the current flow context, perform custom computations, and make HTTP calls to external systems. The value returned by the script becomes the node's output for downstream nodes.

Positioning​

The Code node has one input and one output. It can be placed anywhere in the flow after a trigger node.

Configuration​

The configuration panel includes a JavaScript editor with:

  • Syntax highlighting (ES6+)
  • Auto-indentation
  • Line numbering

Accessing flow context​

The flow execution context is injected automatically as the global $ object. Use it to access upstream node outputs and context variables:

const customerId = $('extractData').output.customerId;
const flowName = $context.agentic_flow_name;

return {
greeting: `Processing customer ${customerId}`,
flowName: flowName
};

The $ object is read-only - the script cannot modify the flow state directly.

Available APIs​

APIDescription
fetchStandard Fetch API for HTTP calls to external systems.
JSONStandard JSON utility (JSON.parse, JSON.stringify).
MathStandard Math utility.
DateStandard Date object.

import and require are not supported - external libraries cannot be loaded.

Return value​

The script must return a JSON object using return. If the script returns undefined or a primitive type, the node fails with:

Invalid Output: Code node must return a JSON object

Execution limits​

LimitValueConfigurable
Timeout10 secondsNo
Maximum memory8 MBNo

These limits are system-level and cannot be changed by the user.

Error behavior​

ScenarioBehavior
Script returns non-JSON valueNode fails: Invalid Output: Code node must return a JSON object
Timeout exceededNode fails: Execution Timeout. Node state → Failed.
Unhandled exception in scriptNode state → Failed. Error details visible in run log.
Syntax error at save timeNode marked as invalid. Flow cannot be saved.

Key concepts​

TermDefinition
$ objectRead-only reference to the flow execution context, automatically injected into the Code node script.
SandboxIsolated execution environment with resource limits and no access to the filesystem or system variables.