Code Runner
Execute custom JavaScript or Python code in your workflows.
Overview
The Code Runner connector is a built-in utility that runs arbitrary JavaScript or Python in a sandboxed environment as part of a workflow. It's the escape hatch for logic that doesn't fit neatly into the named utility connectors - bespoke parsing, custom math, signature generation, niche string manipulation - without leaving the canvas.
Use it sparingly: prefer a dedicated utility (Array, JSON, Date, Regex, Text) when one exists, because named tools are easier to read, debug, and reason about in Agent Mode. Reach for Code Runner when the logic is genuinely custom, when you need a quick prototype before promoting it to a reusable subworkflow, or when an AI agent is generating code on the fly for a one-off transform.
What You Can Do
The Code Runner connector exposes these tools:
execute-javascript- Run a JavaScript snippet against the workflow inputs and return the result. Standard library available; no network access.execute-python- Run a Python snippet against the workflow inputs and return the result. Standard library available; no network access.
Authentication and Setup
No connection or authentication is required. These tools are built into the platform and available in every workflow by default - just drop a Connector node onto the canvas and pick the tool you need.
Using in a Workflow
Add a Connector node, select Code Runner, and pick a mode:
- Direct Mode - Write the code snippet in the node config and bind workflow variables as inputs. Use this when you know exactly what the code needs to do.
- Agent Mode - An AI agent can generate and execute code to satisfy a goal. Pair this with structured output to validate what the code returns. Powerful for unstructured-data tasks where the agent needs to "write a small helper."
Return a JSON-serializable value (object, array, string, number, boolean). The return value is bound to the workflow variable you name in the node.
Tips
- Prefer named utilities first. If JSON Tools, Array Tools, Date Tools, or Regex Tools can do the job, use them - they're more readable and the AI agent reasons about them better.
- Keep snippets small. Code Runner is for transforms, not for building applications. Break large logic into subworkflows.
- Pass data explicitly. Bind workflow variables to named function inputs rather than relying on globals - it makes the code testable.
- Use it for AI extension. When an AI agent needs custom data shaping that isn't expressible as a named tool, let it write a Code Runner snippet rather than wrestling with prompt tricks.
- Log inputs and outputs. Return both the result and any debug info during development, then trim it out before going live.
Common Pitfalls
- No network access. The sandbox blocks outbound HTTP. Use the HTTP Requests connector for that and pass the response into Code Runner.
- No filesystem. The sandbox is ephemeral. Don't write to disk - pass data through workflow variables.
- Execution timeout. Long-running code is killed. Move heavy work into batched steps or a subworkflow.
- Non-serializable returns. Returning a class instance, Date object, or function breaks the JSON serialization step. Return plain values.
- Hard-to-debug code in production. A 50-line Python snippet inside a node is invisible to teammates. Promote stable logic into a documented subworkflow.
Common Use Cases
- Use Code Runner to Extend AI Workflows with Custom Logic
- Use AI to Clean and Normalize Messy Data
- Build a Reusable Subworkflow Library
- Chain Multiple AI Steps for Complex Analysis
- Use AI Agents to Process Unstructured Data
Related Articles
For technical API details and field specifications, see the Code Runner documentation.