How Gemini Managed Agents Works under the Hood
You can go from zero to a working agent in five lines. One API call, and the response comes back with a finished PDF, charts, and a summary.
Python
=
=
What most people miss: this is not a single model call that returns text. Behind that one call, a sandbox boots, skills get loaded, and the model enters a loop where it reasons, picks tools, executes code, reads the output, and repeats until the task is done.
The Execution Loop, Step by Step#
interactions.create() does more than send a prompt. It spins up a full execution environment.
User
Your code
Gemini API
Orchestrator
Gemini 3.5 Flash
Reasoning
Sandbox
Linux VM
- You send a prompt to the Gemini API
- The API boots a sandbox, routes your prompt to the model, dispatches tool calls, and collects results
- Gemini 3.5 Flash plans and picks tools, looping until the task is complete
- Code runs inside an isolated Linux VM, not on your machine
Prompt
Write a python script that prints hello world and execute it.
Explore each step#
Request: Your prompt hits the Interactions API via HTTPS. The API accepts it and starts orchestrating the interaction server-side.
1 / 10
Inside the Sandbox#
Each interaction gets its own isolated Linux container. The agent can install packages, run scripts, read and write files, and browse the web. The sandbox runs Ubuntu with 4 vCPU and 16 GB RAM. Environment compute is not billed during preview (you pay only for model tokens).
Environments can persist across interactions. The first call returns an environment_id you pass back to keep files and state intact. See the Environments documentation for sources, networking, and lifecycle details.
Python
# Turn 1: sandbox is created
=
# Turn 2: same sandbox, files persist
=
From Prompt to Production Agent#
The execution loop is the same whether you are experimenting or running in production. The difference is how much configuration you want to provide upfront.
- Ad-hoc call: Send a input with
environment="remote".
Python
=
- Add instructions and skills: Use
system_instructionorAGENTS.mdto customize behavior and provide skills viasources.
Python
=
- Save as a managed agent: Once your setup is stable, persist it with
client.agents.create(). Each invocation forks a fresh sandbox from the base environment.
Python
=
- Invoke by ID: Reference the agent ID on every call. Same loop, no config to repeat.
Python
=