Code
The Code node runs your own code as a step in a workflow, in Python, JavaScript or TypeScript.
Screenshot placeholder
The palette describes it as "Run custom code".
When to use it
Use it when no other node does what you need and you are comfortable writing a small piece of code. For a simpler form that focuses on one language, see Python or JavaScript.
Settings
| Field | What it does | Notes |
|---|---|---|
| Language | The language the code is written in | Python 3.12 (default), JavaScript (Node 20) or TypeScript (Deno) |
| Code | Your code | See the hints below |
| Dependencies (one per line) | Packages the code needs | For Python these are pip packages, otherwise npm packages. Placeholders are requests and pandas for Python, lodash and axios otherwise |
| Output key | The name the result is stored under | Default code_output |
| Run in sandbox (isolated) | Runs the code in an isolated environment | On by default |
The hint under Code depends on the language:
- Python: "Function must be named run(input: dict) -> dict".
- Other languages: "Export default async function run(input)".
A new node starts with this Python code:
def run(input: dict) -> dict:
# Your logic here
return {"result": input}
Inputs and outputs
| Handle | Where | Purpose |
|---|---|---|
| Input | Top | The step that comes before. Its data reaches your function as input |
| Output | Bottom | Continues the workflow with the value your function returns, stored under the Output key |
The node card shows the chosen language.
Example
This is an illustrative example. You want to add a field to the data.
- Keep Language on Python 3.12.
- In Code, return a new dictionary built from
input, with your extra field. - Read the result in the next step using the Output key,
code_output.
Tips
- Keep the Run in sandbox (isolated) switch on unless you have a reason to turn it off.
- Name the function exactly as the hint says, or the node will not be able to find it.
- When you change the language, review the Code box. Changing it does not rewrite the starter code for you, as far as the settings show.