Skip to main content

Purpose

The Code node runs your own Python code as a step in a workflow. Use it for data transformation, custom logic, calculations, reshaping data between nodes, or anything that’s easier to express in code than with other nodes. Like every other node, the Code node receives inputs from upstream nodes through the workflow’s variable store and returns output that downstream nodes can use. It’s the escape hatch for the moments when a quick bit of Python is clearer than wiring together a chain of nodes.
Python is the only supported language today.

When to use Code vs other nodes

Reach for the right node for the job. The Code node is for logic you write yourself — not for talking to the outside world.
NodeUse it for
CodeCustom logic, calculations, and data transforms you express in Python
ToolActing on external systems via MCP (email, calendar, databases, files)
AgentLLM reasoning, interpretation, and decisions over natural language
APIDirect HTTP calls to external services
If you can describe the step as “take this data and reshape/compute it,” use a Code node. If the step needs to reach an external system or service, use a Tool node or API node instead.

How it works

1

Inputs arrive from upstream nodes

The Code node reads its inputs from the variable store, exactly like other nodes. Data produced by previous nodes — and any files passed in as inputs — are available to your code.
2

Your Python runs in an isolated sandbox

Your code executes inside a strict, single-use sandbox with a working directory of its own. Each run is fully isolated and cannot see other executions or the platform itself.
3

Output is captured

The value your code returns becomes the node’s output. Console output is captured for debugging, and any files your code writes are registered as downloadable workflow files.
4

Downstream nodes consume the result

Your output is written to the variable store so subsequent nodes can reference it.

Writing code

Inside the node you write plain Python. You receive the upstream inputs and return a result that downstream nodes can use. A short example of the kind of code you’d write:
# Reshape and enrich rows coming from an upstream node
rows = inputs["records"]

cleaned = []
for row in rows:
    cleaned.append({
        "name": row["name"].strip().title(),
        "email": row["email"].lower(),
        "total": round(row["price"] * row["quantity"], 2),
    })

total_revenue = sum(item["total"] for item in cleaned)

return {
    "records": cleaned,
    "total_revenue": total_revenue,
    "record_count": len(cleaned),
}
The returned value flows into the variable store and is available to downstream nodes.
There’s a size cap on the code you submit (around 50,000 characters), and captured console output is truncated if it gets very large (around 30,000 characters). Keep code focused and avoid printing huge payloads.

The sandbox

Code nodes run in a strict sandbox so that custom code stays safe and contained.

No network access

Code can’t make outbound network calls. Use a Tool or API node to reach external services, then pass the results in.

Least privilege

Code runs as a non-root user with CPU, memory, and process limits.

Full isolation

Each run gets its own throwaway environment. Code can’t see other executions or the platform itself.

Wall-clock timeout

A time limit stops runaway code so a single step can’t run forever.
Because the sandbox has no network access, you cannot call external APIs from inside a Code node. To bring in external data, use a Tool node (MCP) or an API node earlier in the workflow, then pass the results into the Code node.

Working with files

The Code node gets a working directory you can read from and write to.
  • Input files — Files passed in as inputs are available for your code to read. Input files are limited to the current project.
  • Output files — Any files your code writes out are captured and registered as downloadable workflow files. This means a Code node can produce a CSV, report, or image that later nodes — or you — can download.
# Read an input file, transform it, and write a downloadable result
import csv

with open(inputs["source_file"], newline="") as f:
    rows = list(csv.DictReader(f))

with open("summary.csv", "w", newline="") as out:
    writer = csv.writer(out)
    writer.writerow(["category", "count"])
    # ... write summarized rows ...

return {"rows_processed": len(rows)}
The summary.csv your code writes is captured as a downloadable workflow file.
Operator note: Operators can run the sandbox on Docker (typical for self-hosted and development) or Kubernetes (typical for production). This is transparent to workflow builders — the experience and limits are the same either way.

Best practices

The sandbox has no network. Fetch data with a Tool or API node first, then transform it in the Code node.
Return a dictionary with clearly named fields so downstream nodes can reference exactly what they need from the variable store.
Console output is truncated when very large. Print only what you need for debugging, and pass real results through the return value.
For reports, exports, or images, write a file rather than returning a giant string. Output files become downloadable workflow files.
A wall-clock timeout stops runaway code. Keep loops bounded and avoid heavy work that won’t finish in time.

Next steps

Workflow overview

See how nodes connect and how data flows through a workflow

Tool node

Reach external systems via MCP, then pass results into Code

Agent node

Add LLM reasoning when a step needs interpretation or decisions

Memory system

Understand the variable store that feeds your Code node