Code
Run arbitrary Python logic inside a workflow node. The Code node gives you a full Python function body with access to the upstream input value and workflow context.
Use Code when:
- You need logic that cannot be expressed with Transform, If, or Switch (loops, calculations, string manipulation, data processing)
- You want to use a Python library that is not available as a built-in plugin
- You need to transform arrays, perform arithmetic, or build complex conditional logic
| Handle | Type | Description |
|---|---|---|
input | any | The upstream value passed into your function as the input variable. |
| Handle | Type | Description |
|---|---|---|
result | object | The value returned by your function. Must be a Python dict or JSON-serializable value. |
The result is accessed in downstream nodes as {{ code.* }}.
| Setting | Type | Description |
|---|---|---|
language | enum | Always python for now. |
code | code editor | The Python function body. The input and ctx variables are pre-injected. |
Your code runs inside an async Python function. The following variables are available:
| Variable | Type | Description |
|---|---|---|
input | any | The value connected to the input handle |
ctx.workflow_id | string | The current workflow's ID |
ctx.run_id | string | The current execution run's ID |
Return a dictionary or any JSON-serializable value:
# input is the upstream value
return {
"result": input["amount"] * 1.1,
"formatted": f"${input['amount'] / 100:.2f}"
}
Extract the most recent commit from a GitHub push event and format a Slack message:
commits = input.get("commits", [])
if not commits:
return {"message": "No commits in this push."}
latest = commits[0]
return {
"message": f"New commit by {latest['author']['name']}: {latest['message'][:80]}",
"url": latest["url"],
"author": latest["author"]["name"]
}
Packages listed in the workflow's Python dependencies are installed automatically at runtime. Add packages through the workflow settings, not inside the code node itself.
Standard library packages (like json, re, datetime, os) are always available.
import os
api_key = os.environ.get("MY_API_KEY", "")
Set environment variables in the Env Vars page.
- Return type: Your code must
returna value. If you returnNoneor forget the return statement,{{ code.result }}will benulldownstream. - Async: The function context is async. You can use
awaitfor async operations, but standard synchronous code works withoutawait. - Input is optional: If nothing is connected to the
inputhandle,inputwill beNone. - Errors: An unhandled exception in your code node will fail the entire execution path. Use
try/exceptto handle expected failures gracefully.
- Transform — reshape data without code
- HTTP Request — call APIs (no code needed)
- Environment Variables — store secrets and config
