Gemini 3 + 代码执行
Gemini's calculator runs on Google's servers — not yours
- response
- execution_result
- usage_metadata
Language models are terrible at arithmetic but great at writing code that's good at arithmetic. Gemini3WithCodeExecution wires that up: you ask for something computational, Gemini writes Python, runs it, sees the output, and answers based on the actual result - all in one request. The default prompt ("compute the first 20 Fibonacci numbers") is a perfect demonstration of why this matters: left to its own weights, the model might recite a plausible-looking but wrong sequence; with code execution, it computes and then reports.
This is the node for math, data analysis, and any "don't guess, calculate" job. The key thing to internalize: the code runs on Google's side, inside the API's sandboxed code-execution tool. You never see a local process, and you can't use it to run code on your machine. What you get back is the answer plus the evidence - execution_result carries the generated code and its result as JSON.
How it works
The request attaches a code_execution tool to generateContent. The model responds with an executableCode part, Google executes it server-side, and the result comes back as a codeExecutionResult part alongside the final text. The node splits the response: text goes to response, and every executableCode/codeExecutionResult pair gets serialized into the execution_result JSON - so you can audit exactly what code produced the answer. There's no thinking-level toggle on this node's schema in the current build, but the default request path uses the model's normal configuration.
Inputs and outputs that matter
prompt- the computational task. Be specific about what you want computed and in what form; the model decides how to implement it.- The four standard auth/model fields.
Outputs: response (the model's explanation or final answer), execution_result (JSON containing code and result - this is the evidence trail, wire it to a display if you want to see the actual Python), and usage_metadata (token counts).
Install
Standard for the pack. ComfyUI Manager (search "ComfyUI-Gemini-3") or:
cd ComfyUI/custom_nodes
git clone https://github.com/xuchenxu168/ComfyUI-Gemini-3
cd ComfyUI-Gemini-3
pip install -r requirements.txt
No downloads. Google AI Studio key via api_key field, config.json, or GEMINI_API_KEY.
Common issues
- "Where did my script run?" - it ran on Google's sandbox, not locally, and it was never a local process. If you wanted to run code on your own machine, this is the wrong tool; look at a local-code execution node instead.
- Empty
execution_result- the model may answer from memory without invoking code, especially for easy questions. If you need code guaranteed, phrase the prompt to force it ("compute using code execution"). - No local files, no network beyond Google's sandbox - the executed code can't touch your machine or your images. Don't plan a workflow around it reading a local file.
- Keep temperature default - the pack recommends 1.0 across the board; for a calculation node you generally want the model to just write the code, so the default is fine as-is.
For a workflow that needs computation and a guaranteed data shape, the pack's structured output node can enable code execution alongside a JSON schema - the two compose well.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| prompt | STRING | 计算斐波那契数列的前20项 | — |
| api_provider | COMBO | 1 options: google | |
| api_key | STRING | — | |
| model | COMBO | gemini-3-pro-preview | 1 options: gemini-3-pro-preview |
| thinking_level | COMBO | high | 2 options: high, low |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| response | STRING | — |
| execution_result | STRING | — |
| usage_metadata | STRING | — |