Reference · Tools

Grok Code Interpreter

Execute code using Grok\

Action AI v1

Grok Code Interpreter hands a task to Grok and lets it write and execute code to solve it, returning the response text along with the interpreter's results. Use it where the answer needs computing rather than recalling — reconciling figures across rows, or transforming an awkward data shape that would take a chain of nodes to express.

Node type
Action
Parameters
6
Outputs
Output, Error
Credentials
xAI

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

DirectionPort(s)
InputInput
OutputOutput, Error

Credentials

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

Parameters

ParameterTypeRequiredDefaultDescription
ModeloptionsNoPlatform defaultThe 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 PromptstringNoOptional system prompt to set the behavior and context for code interpretation. Supports expressions like {{ $json.persona }}.
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.
OptionscollectionNo{}Optional generation and output settings — add only the fields you want to override.
— TemperaturenumberNo1Controls randomness. Lower values are more deterministic. Range: 0-2.
— Max TokensnumberNo4096Maximum number of tokens to generate in the response.
— Response Field NamestringNoresponseThe output field name where the AI response text will be stored.
— Include CodebooleanNotrueWhether to include the code interpreter result details in the output.
Include InputbooleanNofalseWhether to include the original input item fields in the output alongside the AI response.
Max ConcurrencynumberNo5Maximum 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:

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

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

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

ModeBehavior
stopHalts workflow on first error
continueSkips failed items, passes successful ones through
errorPortRoutes 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.

Frequently asked questions

When should I use this rather than writing the logic myself?

When the transformation is one-off, awkward to express as static node logic, or depends on the shape of data you only see at runtime. For stable, repeatable logic a code node you control is cheaper and more predictable.

Where does the code actually run?

Inside xAI's code interpreter as part of the Responses API call — nothing executes in your workflow environment. Use Execute Command if you need something to run on your own infrastructure.

What does the output contain?

The assistant's response text alongside any code interpreter results, so you can see both the conclusion and what the code produced to reach it.

Which credential does it need?

An xAI credential with access to a Grok model that supports the code interpreter tool.

Build with the Grok Code Interpreter node

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

Open BusyBot

Last updated . Spotted something wrong? Tell us.