<!-- BusyBot node reference — https://busybot.net/tools/gemini-code-execution/ -->

> Node: Gemini Code Execution (`gemini_code_execution`) · Action · v1
> Category: AI · Credentials: Google AI (`googleAi`)
> Updated: 2026-08-16

# 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

| Direction | Port(s) |
|-----------|--------|
| Input | `Input` |
| Output | `Output`, `Error` |

## Credentials

This tool requires **Google AI** credentials.
See the [Credentials Guide](https://busybot.net/credentials/google-ai/) for setup instructions.

### Parameters

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| Model | `options` | No | (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 Prompt | `string` | No | — | Optional system instruction that sets the behavior and context for code execution. Supports expressions. |
| User Message | `string` | Yes | — | The 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 URIs | `string` | No | — | Optional. 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. |
| Options | `collection` | No | `{}` | Optional generation and output settings — add only the fields you need. |
| — Temperature | `number` | No | `1` | Controls randomness. Lower values are more deterministic. Range: 0-2. |
| — Max Output Tokens | `number` | No | `8192` | Maximum number of tokens in the generated response. |
| — Response Field Name | `string` | No | `response` | The key name in the output JSON where the response text will be stored. |
| — Include Code | `boolean` | No | `true` | Whether to include the generated executable code and language in the output. |
| Include Input | `boolean` | No | `false` | Whether to merge the input item JSON into the output item. |
| Max Concurrency | `number` | No | `5` | Maximum 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.

```json
{
  "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:

```json
{
  "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:

```json
{
  "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:

```json
{
  "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

| Mode | Behavior |
|------|----------|
| **stop** | Halts workflow on first error |
| **continue** | Skips failed items, passes successful ones through |
| **errorPort** | Routes 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.