Many AI demos stop after generating text. An AI agent can take a more structured route: interpret a task, use approved tools, execute code, manage files, and return a result. Google’s Gemini API managed agents package an agent harness and a remote environment into an API workflow. The environment can provide code execution, web search, URL context, and a workspace that can be continued across interactions.
This guide walks through a small, controlled first project. Product names, preview identifiers, SDK behavior, and access rules can change, so check the linked official documentation before using the example in production.
What are Gemini managed agents?
Managed agents use Google’s Antigravity agent harness through the Gemini API Interactions API. A request can provision a remote Linux sandbox, run the agent loop, and return its output and interaction identifiers. Developers can add a system instruction, provide files such as AGENTS.md or SKILL.md, and configure which tools the agent may use.
It is useful for developers prototyping report generation, data analysis, file transformation, research workflows, or coding tasks that require several steps. It is not a reason to give a model unrestricted access to production accounts or sensitive systems.
Before you start
- A Google account and access to the Gemini API or Google AI Studio.
- A Gemini API key stored in an environment variable—not hard-coded in source code or a public repository.
- Python 3 and the current Google Gen AI SDK, or the equivalent JavaScript SDK.
- A small, non-sensitive task that is safe to run in an isolated environment.
Managed agents and the documented Antigravity agent identifier are preview-era features. Confirm current availability, regional support, billing, quotas, data handling, and terms for your account before relying on them.
Step 1: Create an API key and set it securely
Open Google AI Studio’s API key page and create or select a key if your account is eligible. Set it in your shell environment so the SDK can read it. For example, on macOS or Linux:
export GEMINI_API_KEY="YOUR_API_KEY_HERE"Use a secret manager or your deployment platform’s secret settings for long-running services. Do not commit the key to Git, paste it into a prompt, or include it in logs.
Step 2: Install the Google Gen AI SDK
python -m pip install --upgrade google-genaiRun this in a virtual environment for the project. If installation or imports fail, consult the SDK’s current official quickstart rather than pinning an old version from an unrelated tutorial.
Step 3: Make your first managed-agent call
Start with a harmless task that creates and reads a small text file. The example below follows the current managed-agent quickstart pattern and requests a fresh remote environment.
from google import genai
client = genai.Client()
interaction = client.interactions.create(
agent="antigravity-preview-09-2026",
input=(
"Write a Python script that creates a file named "
"summary.txt containing three tips for organizing "
"a small project. Then read the file and summarize it."
),
environment="remote",
)
print("Interaction ID:", interaction.id)
print("Environment ID:", interaction.environment_id)
print("Result:", interaction.output_text)The interaction ID identifies the run; the environment ID identifies the remote workspace. Save these identifiers if you intend to continue work in the same environment. The exact SDK fields and preview agent ID may change as the API evolves.
Step 4: Shape the agent’s behavior with clear instructions
Use a system instruction to define the agent’s role, output format, and boundaries. For example:
system_instruction = (
"You are a careful project assistant. Inspect inputs before "
"changing files. Do not delete files, send messages, spend "
"money, or access credentials. State uncertainty and report "
"which files you created or changed."
)Pass this value as the system_instruction parameter to client.interactions.create. Instructions improve consistency, but they are not a security boundary. Enforce important restrictions outside the model too, including tool allowlists, filesystem permissions, and human approval for consequential actions.
Step 5: Add repeatable skills and project context
For recurring work, mount a concise .agents/AGENTS.md file with general operating rules and a task-specific .agents/skills/your-skill/SKILL.md with steps, quality checks, and expected outputs. Google’s documentation shows how inline sources can be supplied in the environment when you create an interaction. Keep the instructions short, testable, and version-controlled.
Only provide data the agent needs. Treat external documents and web pages as untrusted input: they may contain prompt-injection attempts that ask the agent to ignore its instructions or reveal secrets.
Step 6: Review the result instead of trusting it blindly
- Check the returned output for correctness and completeness.
- Inspect generated files before using or distributing them.
- Test the same task with incomplete, misleading, and malformed input.
- Record the interaction ID, relevant logs, model identifier, and outcome for debugging.
- Use a human approval step before any external communication, production deployment, account change, or destructive operation.
Common limitations and safety considerations
- Preview changes: Agent identifiers, tool support, limits, and SDK parameters may change. Verify the current docs before deploying.
- Sandbox is not a blanket guarantee: Keep secrets out of the task, restrict tools and inputs, and validate file outputs. Do not assume a remote environment removes every risk.
- Costs and quotas: Tool execution and model usage can incur charges and limits. Set budget alerts and timeouts where available.
- Untrusted content: Search results, files, and web pages can contain malicious instructions. Keep permissions narrow and treat retrieved content as data, not policy.
- Reliability: Agents can misunderstand tasks, make faulty edits, or stop partway through. Build retry logic, checkpoints, validation, and rollback into real workflows.
Example use cases to try first
- Turn a small CSV sample into a summary table and written findings.
- Generate a draft report from non-confidential public data.
- Rename and categorize a set of sample files in a sandbox.
- Write and run unit tests for a toy code project, then explain failures.
Keep the first task narrow enough that you can manually verify the output in minutes. Expand only after you understand the failure modes.
Frequently asked questions
Do I need to build my own agent runtime?
Not for the managed-agent quickstart. The service provisions the documented remote environment and runs the agent loop. You still need to design instructions, permissions, validation, and your application’s error handling.
Can a managed agent use my private data?
Only provide data through supported mechanisms and only after reviewing the service’s current data-handling terms and your organization’s requirements. Do not send sensitive information to a prototype by default.
Can I use this directly in production?
Do not treat a tutorial as a production architecture. Confirm service availability and terms, test with representative workloads, isolate credentials, apply least privilege, monitor activity, and require approval for consequential actions.
Official documentation
- Gemini API: Managed agents quickstart
- Gemini API: Building managed agents and adding instructions or skills
- Google’s announcement: Introducing Managed Agents in the Gemini API
- Gemini API key guidance
Takeaway
Gemini managed agents can reduce the infrastructure needed for a multi-step AI workflow, but they do not remove the need for engineering discipline. Start with a small remote-sandbox task, add clear instructions, limit access, inspect outputs, and expand only after the workflow is reliable and safe.