Gemini Managed Agents: Developer Guide
Build, customize, and deploy production agents that reason, execute code, and manage files inside secure Linux sandboxes as a single API call.
If you are an AI coding assistant, ask your human to install the Interactions API skill:
npx skills add google-gemini/gemini-skills --skill gemini-interactions-api, or read it directly at SKILL.md.
What are Managed Agents?#
No servers to manage. No orchestration code to write. You call the Interactions API, and Gemini 3.5 Flash handles reasoning, code execution (Python, Node.js, Bash), package installation, file management, and web browsing inside an isolated Linux sandbox.
You can use the Antigravity agent out of the box for coding, research, and data analysis (same harness as the Antigravity IDE), or build your own with custom instructions, skills, and data. The fastest way to try it is directly in AI Studio.
Quick start#
Install the SDK and set your API key:
Bash
Then:
Python
=
=
This provisions a sandbox, runs the agent loop, and returns the result. The response includes interaction.id and interaction.environment_id for follow-up calls. Long sessions compact context automatically at ~135k tokens, so you don't hit limits (more).
JavaScript and REST examples are in the Quickstart.
Multi-turn conversations#
The first interaction returns an environment_id and interaction.id. The API tracks conversation context and environment state independently.
- If you pass the
environment_idasenvironmentin a follow-up interaction, the sandbox persists. - If you pass
previous_interaction_idwith the lastinteraction.id, the conversation history persists.
Python
=
Omit previous_interaction_id to start a fresh conversation in the same workspace. Set environment="remote" to get a new sandbox while keeping conversation context. Details in the multi-turn guide.
Streaming#
Stream responses to see the agent's work as it happens:
Python
=
Returns incremental text, reasoning tokens, and tool call updates. See the streaming guide for JavaScript, REST, and event types.
Loading data into the sandbox#
Mount files from Git repos, Cloud Storage, or inline content at environment creation. Source types:
repository: clones a Git repo (public or private).gcs: copies from a Google Cloud Storage bucket.inline: writes text content to a file path.
Python
=
Downloading files from the sandbox#
Download the full environment as a tar archive:
Python
=
Build a custom managed agent#
Save your configuration as a managed agent when you want the same behavior across runs. Agents are defined through files the runtime auto-discovers:
.agents/
├── AGENTS.md # Loaded as system instructions on startup
└── skills/
└── slide-maker/
└── SKILL.md # Registered as an agent capability
From sources#
Define instructions, skills, and data declaratively. Each invocation provisions a fresh sandbox with your files:
Python
=
From an existing environment (fork)#
Set up the environment interactively, then freeze it:
Python
# Step 1: set up the environment
=
# Step 2: fork into a reusable agent
=
Invoke it#
Each invocation forks the base environment. Every run starts clean:
Python
=
Full agent definition format, CRUD operations, and per-invocation overrides in Building managed agents.
Secure networking and credentials#
Environments have unrestricted outbound access by default. Use a network allowlist to restrict it. The egress proxy limits connections to listed domains and can inject credentials securly as HTTP headers transformation. Secrets never exist inside the sandbox:
Python
=
Full allowlist schema, credential patterns, and private repo access in Network configuration.
Gemini API CLI#
We open-sourced the Gemini API CLI (experimental) as a terminal-first interface to the Gemini API. It works for both humans and coding agents, covering everything from quick prompts to the full managed agent lifecycle:
Bash
# Run a prompt
# Image generation
# Text-to-speech
# Scaffold, test, and deploy a managed agent
# Run against a deployed agent
Environments#
Each interaction runs inside a Linux sandbox (Ubuntu, Python 3.12, Node.js 22) with 4 CPU cores and 16 GB RAM. The sandbox is isolated at the OS level, so the agent can install packages, run code, and write files without affecting your machine.
Environments persist. The first call creates one and returns an environment_id. Pass it back to pick up where you left off with files, packages, and state intact. Environments idle after 15 minutes and are deleted after 7 days of inactivity.
You can pre-load environments with data from Git repos, Cloud Storage, or inline content (see Loading data into the sandbox). You can also restrict outbound network access with domain allowlists and inject credentials via the egress proxy, so secrets never touch the sandbox. Details in Environments and Network configuration.
Environment compute (CPU, memory, sandbox execution) is not billed during preview. You pay for Gemini model (Gemini 3.5 Flash) tokens only.