code_execution (Gemini)
Tool : A precise action the AI can call · requires gemini-api
Python executed on Google's side, results returned to the model.
Practical and included; isolated execution at Google.
Security reflects where data goes, requested permissions and incidents on record at the verification date. It is not a guarantee of zero risk: check the deployment mode and the connections you enable.
What it does, concretely
When a language model needs to perform precise calculations, process files, or solve equations, text generation alone is not enough. The code_execution tool in the Gemini API allows the model to generate Python code, run it in an isolated environment hosted by Google, and then use the results to iteratively refine its response.
In practice, when you enable the tool in your request, Gemini can write a Python script, send it to a secure runtime environment, retrieve the output, and continue reasoning from it. The model can repeat this cycle up to five times if an error occurs. Execution is limited to 30 seconds per call.
This tool is aimed at developers integrating the Gemini API who need reliable calculations, CSV or text file processing, or Matplotlib chart generation directly within the model's response. It also works in multi-turn conversations through the previous_interaction_id parameter.
However, it is not suitable for those who want to execute code in a language other than Python: Gemini can generate code in other languages, but cannot run it through this tool. It is also not intended for end users without API access.
What it offers
- ·Python code execution in an isolated environment hosted by Google, at no additional cost beyond the tokens consumed.
- ·Iterative reasoning: the model can re-run execution up to five times to correct errors before providing a final response.
- ·Support for file input (CSV, text) and Matplotlib chart generation returned as inline images in the response.
- ·Image processing with Gemini 3 Flash: the model can write and execute Python code to crop, annotate, or analyze images passed as input.
- ·Use in multi-turn conversations via the previous_interaction_id parameter to chain exchanges with context memory.
- ·Compatibility with Python, JavaScript SDKs and the REST API for flexible integration depending on the development environment.
- ·Maximum execution time of 30 seconds per call, with automatic error return if this limit is exceeded.
In practice
- Price
- Freemium
- Commercial use
- Commercial use: yes
- Available on
- api
- Host
- gemini-api
- FR interface
- No
Security and data
- Rating
- Security: one caveat, see the card
- Capabilities
- readswritesexecutesnetwork
- Your data
- Data with the vendor
- Maintenance
- Active
Links and repository checked on 25 October 2026 · added on 1 June 2024
How to install code_execution (Gemini)
pip install google-genai