- Home
- Resources
- Integrations
- Code Tool
n8n Code Tool nodeConfigure Code Tool in n8n.
The n8n Code Tool node turns a few lines of JavaScript or Python into a tool an AI agent can call on its own. Four parameters cover it: a name, a description the model reads to decide when to run it, the language and its code box, and an optional input schema.
Verified Trustpilot reviews · AI, automation & growth agency
What does the n8n Code Tool node actually do?
The Code Tool node is a sub-node, which means a small node you plug into a port of a bigger one rather than a step in the main flow. It holds a snippet of JavaScript or Python and hands it to an agent as a callable tool. When the model decides the tool fits the request, n8n runs the snippet with the text the model produced and passes the returned string back into the conversation.
The first use it earns is the calculation no model should be guessing at. A pricing rule, a VAT split, a working-day count between two dates: you write it once in the JavaScript box, describe it in one sentence, and the agent stops improvising arithmetic. The code reads the model's text through the query property and returns a single string, so the shape of the exchange stays predictable.
The second use is reformatting. An agent built on the AI Agent node often receives messy text and needs it normalized before anything else happens: a phone number cleaned up, a product reference parsed out of a sentence, a date turned into ISO. A dedicated node exists for none of that. Ten lines of Python do it, and the agent calls them only when it needs them.
The third use is a guarded input. Turn Specify Input Schema on and the model has to send a structured object that n8n validates before your code runs. That is what makes a code tool safe to put next to tools that write somewhere real, such as a row in Google Sheets or a message to Slack.
Prefer a different node when the job is not really code. Calling a service that already has an n8n node is better served by that node wired as a tool, and a transformation that happens on every item, not on the agent's decision, belongs in the main flow rather than here. A model that has to be talked into calling your function usually needs a sharper description, not more code.
Two limits are worth knowing before you build on it. Python runs in beta on this node, and the tool returns one string, so anything structured has to be serialized by your own code. The model provider behind the agent, OpenAI or another one, bills its own API calls; n8n adds nothing on top. If you want the wiring walked through end to end, the n8n training covers agents and their sub-nodes.
Where does the Code Tool node plug in?
n8n splits its AI nodes in two: a root node sits in the workflow and receives items, and sub-nodes hang off its ports. The Code Tool node is a sub-node, so it never runs by itself and has no main input.
Output (what it plugs into)
- Tool
ai_tool
01Tool
This is the single port the node exposes. You drag its connector onto the tool port of a root node, and from that moment the model can list it, choose it and call it like any other tool in the same agent.
Key parameters
- Required: with nothing connected to it, the node is inert. A sub-node never executes on its own.
- AI Agent: the usual host, a conversational or task-running agent.
- AI Agent Tool: an agent itself wired as a tool of another agent.
- MCP Server Trigger: when the tool has to be exposed to an outside client.
What are the 4 parameters of the Code Tool node?
The Code Tool node has 4 parameters. For each one: the node as you configure it in n8n, what the parameter changes, and our field notes.
Parameters index
Name
nameWhat you see in n8n
Notes & use cases
Along with the description, the name is what the model reads when it scans the tools available to it. It is a label for a machine, not a heading for a human, and the placeholder My_Tool shows the register expected: short, no spaces.
Key parameters
- Name: a plain text field with nothing behind it. Something like
compute_shippinglands better with a model than a full sentence would.
Description
descriptionWhat you see in n8n
Notes & use cases
Everything the model knows about when to reach for this tool sits in this field. The node's own placeholder is a good template: it states the job, then states what the input string should contain, in that order.
Key parameters
- Description: free text. Write the trigger condition and the expected input shape, for instance a sentence saying the tool returns a random color and that the input is a comma separated list of colors to exclude.
Language
languageWhat you see in n8n
Notes & use cases
This selector decides which code box appears underneath, and it changes how your snippet reads the agent's input. Pick it before writing anything, because switching later means rewriting the accessor.
Key parameters
- Language: two options,
javaScript(JavaScript) andpython(Python (Beta)). - JavaScript: the code box for the first option. The input arrives in the
queryproperty and the snippet has to return a single string. - Python: the box for the second. Same contract, except the input is read from
_query.
Specify Input Schema
specifyInputSchemaWhat you see in n8n
Notes & use cases
Off, the tool takes whatever string the model writes. On, n8n requires the model to send input in a declared format and validates it against that schema before the code runs.
Key parameters
- Specify Input Schema: the toggle itself. It reveals the three fields below.
- Schema Type:
fromJson(Generate From JSON Example) builds the schema from a sample object,manual(Define using JSON Schema) has you write it out. - JSON Example: the sample object the first mode reads.
- Input Schema: the schema itself, in JSON Schema format. The
$refssyntax is not supported.
Need help automating Code Tool with n8n?
A person reads every message.
Code Tool node, the questions that come next
01Is the Code Tool node free to use in n8n?
02What do you need to authenticate before it works?
03What are the limits of the n8n Code Tool node?
04What has to be connected, and where do you start?
05n8n or Make for a custom agent tool?
Get our weekly integration tips.
No spam. Unsubscribe anytime.
