NanoBanana - Text Gen + Code Execution
Let Gemini write the Python and run it too
- network
- text
- executed_code
- exec_result
This is the NanoBanana2 text node for the questions that aren't just "write me a paragraph." TextGenCode gives Gemini the ToolCodeExecution tool, which means the model can write Python, run it in Google's sandbox, look at the output, and iterate - then hand you the final answer and the code it ran, separately. "What's the standard deviation of these numbers?" "Plot this data." "Parse this messy JSON." You get the reasoning and the receipt.
It defaults to gemini-2.5-pro with a chilly 0.1 temperature - the pack author clearly wants this one deterministic - and honestly, for calculation-heavy prompts that's the right instinct. Want it cheaper and faster? Swap in gemini-2.5-flash and it's usually fine for simple math and one-liner wrangling.
How it works
Under the hood it builds a GenerateContentConfig with tools=[Tool(code_execution=ToolCodeExecution())] and lets the model call that tool during generation. Then it walks the response parts and pulls out three things: the model's final text, any executable_code chunks it actually ran, and the code_execution_result outputs. Multiple code/result pairs get joined with --- separators so you never lose part of the trace.
One thing to internalize: the code runs in Google's sandbox, not on your machine. That's the whole point - no local execution, no environment to manage - but it also means no local file access. Gemini can't read your disk and you can't read its filesystem afterwards; you get the printed output only. For "read this CSV in ComfyUI's input folder" you'd want a different approach.
The inputs
- api_key, model, custom_model, prompt - the usual quartet. Multiline prompt, 35 model options, custom override.
- temperature - the only sampling knob here, default 0.1.
- network - optional
NB_NETWORKroute for proxy egress, same as every other node in the pack.
Outputs (three STRINGs):
- text - the model's final answer.
- executed_code - the Python it actually ran.
- exec_result - what that code printed.
Wire text into your ShowText or downstream prompt; executed_code and exec_result are gold for debugging - you can see exactly what it did and catch it hallucinating a calculation.
Installing it
Same story as every node in this pack: ComfyUI Manager → search NanoBanana2, or
cd ComfyUI/custom_nodes
git clone https://github.com/IxMxAMAR/ComfyUI-NanoBanana2
pip install google-genai
Python 3.10+, google-genai >= 0.8.0, an API key from aistudio.google.com. No model files.
Common issues
Tool-calling burns extra tokens - every code iteration is billed - so "run this 1000-row analysis" can surprise you on the invoice. That's what the pack's Cost Estimator node is for. If the model returns a plan but no exec_result, it may have hit a sandbox limit or decided code wasn't needed; check the answer text first. And remember every run re-executes even with identical inputs, so leave this out of loops you don't want billed repeatedly.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| api_key | STRING | — | |
| model | COMBO | gemini-2.5-pro | 35 options: gemini-pro-latest, gemini-flash-latest, gemini-flash-lite-latest, gemini-3-pro-preview, gemini-3-flash-preview, gemini-3.1-pro-preview, +29 |
| prompt | STRING | — | |
| custom_modelopt | STRING | — | |
| temperatureopt | FLOAT | 0.100–2 | — |
| networkopt | NB_NETWORK | Optional. Wire a NanoBanana - Network Route node here to route this request through that proxy (e.g. US egress). |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |
| executed_code | STRING | — |
| exec_result | STRING | — |