Reference · Tools

Gemini Code Execution

Execute code using Gemini\

Action AI v1

Gemini Code Execution hands a prompt to Gemini with the code-execution tool enabled, so the model writes Python, runs it, and uses the result to answer. You get the response text, the code it wrote, that code's output and the execution outcome. Use it for work static nodes cannot do — ad-hoc calculations over incoming data, or parsing an awkward file format on the fly.

Node type
Action
Parameters
7
Outputs
Output, Error
Credentials
Google AI

Gemini Code Execution

Execute code using Gemini’s built-in code execution tool.

Overview

Gemini Code Execution uses the Google Gemini generateContent API with the code_execution tool enabled. The model can write and execute Python code to solve problems, perform calculations, data analysis, and more. The response includes the generated text, executable code, code output, and execution outcome. Supports model selection, system prompts, and generation config.

Category: AI
Tool Name: gemini_code_execution
Version: 1

Appearance: Icon: gemini | Color: #ffffff

Node Type

Action — processes input items and produces output

Input / Output

DirectionPort(s)
InputInput
OutputOutput, Error

Credentials

This tool requires Google AI credentials. See the Credentials Guide for setup instructions.

Parameters

ParameterTypeRequiredDefaultDescription
ModeloptionsNo(current default)The Gemini model to use for code execution. Pick a specific version — labels are pinned, not aliased to “latest”.
Options: the Gemini chat models available to your workspace — pick one from the dropdown.
System PromptstringNoOptional system instruction that sets the behavior and context for code execution. Supports expressions.
User MessagestringYesThe message or prompt to send. The model will write and execute code as needed. Falls back to item.message or item.prompt if empty. Supports expressions like {{ $json.task }}.
File URIsstringNoOptional. fileUri value(s) from the Gemini File Upload tool. Pass a single URI or a JSON array for multiple files. Files are sent as multimodal context alongside the message. Falls back to item.fileUris if empty. Gemini File API retains uploads for 48 hours. Supports expressions.
OptionscollectionNo{}Optional generation and output settings — add only the fields you need.
— TemperaturenumberNo1Controls randomness. Lower values are more deterministic. Range: 0-2.
— Max Output TokensnumberNo8192Maximum number of tokens in the generated response.
— Response Field NamestringNoresponseThe key name in the output JSON where the response text will be stored.
— Include CodebooleanNotrueWhether to include the generated executable code and language in the output.
Include InputbooleanNofalseWhether to merge the input item JSON into the output item.
Max ConcurrencynumberNo5Maximum number of items to process concurrently.

Output Data

One request per input item, and one output item per input item. The model’s narrative answer lands on the field named by Response Field Name (response by default); the code it wrote and what that code printed land beside it. The rest of the input item JSON is dropped unless Include Input is on; binary data on the input item is forwarded unchanged.

{
  "response": "The model's narrative answer, with the code blocks stripped out",
  "code": "print(sum(range(10)))",
  "language": "the language the API reported for that code",
  "codeOutput": "45\n",
  "codeOutcome": "the API's outcome flag for the execution",
  "model": "the model that answered",
  "usage": { "promptTokenCount": 620, "candidatesTokenCount": 1840 }
}
  • code and language are the code the model executed and the language the API reported for it. Both are omitted when Include Code is off, and when the model answered without running any code.
  • codeOutput is what the execution printed and codeOutcome is the API’s outcome flag for that run. Both are omitted when no code ran. A script that fails is not a node error — the item still leaves through the Output port carrying the failure in codeOutput and codeOutcome, so branch on codeOutcome if you need to react to it.
  • response holds only the model’s prose. The code itself is never inside it, so a downstream node reading the response field will not have to strip code fences.
  • usage is the token accounting the API returned for that call.

Reference the result downstream by expression, e.g. {{ $json.codeOutput }}.

Usage Examples

  • Calculate complex math expressions using Gemini code execution
  • Analyze data by having Gemini write and run Python code
  • Generate charts or computations with code execution
  • Solve programming problems with executable code
  • Process numerical data with Gemini’s Python sandbox

Example Configuration

Minimal — one computation per item:

{
  "type": "gemini_code_execution",
  "parameters": {
    "userMessage": "Calculate the first 20 Fibonacci numbers and return them as a JSON array."
  }
}

Deterministic analysis with the code kept for auditing:

{
  "type": "gemini_code_execution",
  "parameters": {
    "systemPrompt": "You are a data analysis expert. Write clean, commented Python and validate your numbers before answering.",
    "userMessage": "For the dataset {{ $json.values }}, compute the mean, median and standard deviation, and flag outliers using the IQR method.",
    "includeInput": true,
    "maxConcurrency": 3,
    "options": {
      "temperature": 0,
      "maxOutputTokens": 8192,
      "responseFieldName": "analysis",
      "includeCode": true
    }
  }
}

High-volume transformation where only the answer is needed downstream:

{
  "type": "gemini_code_execution",
  "parameters": {
    "systemPrompt": "You transform raw data. Return only valid JSON — no markdown fences, no commentary.",
    "userMessage": "Convert this CSV row into a structured JSON object with appropriate types: {{ $json.csvRow }}",
    "includeInput": true,
    "maxConcurrency": 10,
    "options": {
      "temperature": 0,
      "maxOutputTokens": 1024,
      "responseFieldName": "transformed",
      "includeCode": false
    }
  }
}

Error Handling

ModeBehavior
stopHalts workflow on first error
continueSkips failed items, passes successful ones through
errorPortRoutes failed items to Error output port

Tips

Gemini Code Execution sends a prompt to the Google Gemini API with the code_execution tool enabled, allowing the model to write and run Python code to solve problems autonomously. Use this tool when a workflow requires dynamic computation, mathematical calculations, or data analysis that cannot be handled by static node logic. The output delivers generated response text, the executed Python code, code output, and an execution outcome on the main channel, or routes failures to the error channel.

Frequently asked questions

What exactly comes back from this node?

Four things: the generated response text, the Python the model wrote, the output that code produced when it ran, and the execution outcome. That makes the result auditable rather than a number you have to trust.

Is the code running on my infrastructure?

No. Execution happens inside Google's code-execution tool as part of the Gemini generateContent call, so nothing runs in your workflow environment. For commands on your own machine, use Execute Command instead.

Which credential does it use?

A Google AI credential. The node calls the Gemini generateContent API directly, so the key needs access to the model you select.

Can I steer how it approaches the problem?

Yes — model selection, system prompt and generation config are all exposed, so you can constrain the approach or ask for a specific output format alongside the computed result.

Build with the Gemini Code Execution node

Drop it into a workflow, wire it to an agent, or call it on a schedule. You'll need Google AI credentials first.

Open BusyBot

Last updated . Spotted something wrong? Tell us.