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

> Node: Grok Code Interpreter (`grok_code_interpreter`) · Action · v1
> Category: AI · Credentials: xAI (`xai`)
> Updated: 2026-08-16

# Grok Code Interpreter

> Execute code using Grok's code interpreter via the xAI API.

## Overview

Grok Code Interpreter has Grok write and execute code in a sandbox — calculations, data analysis, generating outputs. The output of the executed code is returned in the assistant message text (the response field); each code interpreter call also exposes its code, status, and structured outputs (logs plus any generated images or files). Supports system prompts, temperature, and max tokens.

**Category:** AI  
**Tool Name:** `grok_code_interpreter`  
**Version:** 1

**Appearance:** Icon: `brain` | Color: `#000000`

## Node Type

**Action** — processes input items and produces output

## Input / Output

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

## Credentials

This tool requires **xAI** credentials.
See the [Credentials Guide](https://busybot.net/credentials/xai/) for setup instructions.

### Parameters

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| Model | `options` | No | Platform default | The Grok model to use for code interpretation. |
| | | | | Options: the Grok chat models currently available — the dropdown tracks the model catalog, so it changes as xAI's line-up changes. |
| System Prompt | `string` | No | — | Optional system prompt to set the behavior and context for code interpretation. Supports expressions like {{ $json.persona }}. |
| 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. |
| Options | `collection` | No | `{}` | Optional generation and output settings — add only the fields you want to override. |
| — Temperature | `number` | No | `1` | Controls randomness. Lower values are more deterministic. Range: 0-2. |
| — Max Tokens | `number` | No | `4096` | Maximum number of tokens to generate in the response. |
| — Response Field Name | `string` | No | `response` | The output field name where the AI response text will be stored. |
| — Include Code | `boolean` | No | `true` | Whether to include the code interpreter result details in the output. |
| Include Input | `boolean` | No | `false` | Whether to include the original input item fields in the output alongside the AI response. |
| Max Concurrency | `number` | No | `5` | Maximum number of items to process concurrently. |

## Output Data

One output item per input item. The assistant's answer — which is where the executed code's result actually lands — is written to the field named by Response Field Name (`response` by default). The rest of the input JSON is carried over only when Include Input is on; binary data from the input item is forwarded.

- `response` — the assistant's answer text, under whatever name Response Field Name is set to.
- `codeInterpreterResults` — added when Include Code is on and the model ran at least one code call. An array with one entry per call, each carrying `id`, `code` (the source the model wrote), `status`, `outputs` (the raw execution artifacts, including any generated images or files), and `logs` (the `outputs` log entries joined into one string).
- `model` — the model that produced the answer.
- `usage` — the token counts reported by xAI for the request.

`logs` is often empty even on a successful run, because the model surfaces the result of the code in its answer text rather than in the log stream. Read `response` for the answer and `codeInterpreterResults` when you need to see the code itself.

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

## Usage Examples

- Calculate complex math expressions using Grok code interpreter
- Analyze data by having Grok write and execute Python code
- Solve programming problems with executable code via Grok
- Process numerical data using Grok's code interpreter
- Generate computational results with Grok

## Example Configuration

Run a computation with the defaults:

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

Analyse item data deterministically and keep the generated code:

```json
{
  "type": "grok_code_interpreter",
  "parameters": {
    "systemPrompt": "You are a data analyst. Always return results as valid JSON.",
    "userMessage": "Parse this CSV and return mean, median, max and min for each numeric column: {{ $json.csvContent }}",
    "includeInput": true,
    "maxConcurrency": 3,
    "options": {
      "temperature": 0.2,
      "maxTokens": 4096,
      "responseFieldName": "analysisResult",
      "includeCode": true
    }
  }
}
```

Convert values in bulk without the code details:

```json
{
  "type": "grok_code_interpreter",
  "parameters": {
    "systemPrompt": "Be concise. Return only the answer, no explanation.",
    "userMessage": "Convert {{ $json.fahrenheit }} degrees Fahrenheit to Celsius.",
    "includeInput": true,
    "maxConcurrency": 10,
    "options": {
      "temperature": 0,
      "maxTokens": 256,
      "responseFieldName": "celsius",
      "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

Grok Code Interpreter sends code execution requests to Grok models through the xAI Responses API, enabling calculations, data analysis, and programmatic output generation. Choose this tool when a workflow step requires numerical computation, statistical analysis, or data transformation where Grok should autonomously write and run the code rather than apply static logic. It outputs the assistant response text alongside any code interpreter results, routing failures to a separate error output.