Antigravity
Python SDK quickstart
Write a minimal agent with the Antigravity Python SDK, tell it apart from the hosted agents in the Gemini API, and keep tools and permissions to the minimum.
This page covers the entry point to the Antigravity Python SDK: writing an agent in Python that runs on your own machine. It is not about using the Antigravity App, the CLI (agy), or the IDE extension, and it is not about the agents that Google hosts and runs inside the Gemini API. This guidebook is an independent, unofficial project; versions, fields, and defaults are subject to the official pages.
After reading, you will be able to write a minimal agent with read-only tools, know how it differs from a hosted agent, and check the tool and policy boundaries before granting more permissions.
The code examples on this page were not actually run. The identifiers and call patterns come from checking the official pages above, not from run results. Try them in a synthetic directory first, then bring them into a real project.
What the SDK is and is not
Section titled “What the SDK is and is not”Google describes it as an SDK for building autonomous agents in Python: a stateful runtime harness that handles tool execution, context management, safety policies, and subagent delegation. Agent is used as an async context manager, and it manages discovery of the underlying program, tool execution, and the session lifecycle.
Compared with neighboring entry points:
| Entry point | Where it runs | What you get |
|---|---|---|
| Antigravity SDK (this page) | Your own Python process and machine | An agent whose tools, policies, and subagents you configure in code |
| Gemini API hosted agents | A Google-hosted sandbox, created with one API call | A ready-made Antigravity agent or Deep Research, used through the API |
| Antigravity CLI / App / IDE extension | Your terminal, desktop, or editor | Interactive use; see Choosing an Antigravity surface |
The hosted agents page says Google provides an isolated Linux sandbox in which the agent reasons, runs code, manages files, and browses the web; the feature is currently in public preview, and the sandbox, credential, and billing rules are all on that page. The SDK overview page explicitly points to that page as the documentation for “cloud-hosted” use. Therefore: the tool and policy configuration on this page does not automatically apply to hosted agents, and the reverse is also true. The hosted page does not compare the two directly; the “Where it runs” column in the table above is a summary of what the two pages describe, not an official comparison table.
Minimal example
Section titled “Minimal example”Install (the official overview page does not state the required Python version; check the package’s release page first):
pip install google-antigravityAuthentication is covered in the next section. Set the environment variable first, then run the script:
export GEMINI_API_KEY=YOUR_API_KEYpython hello_agent.pyhello_agent.py, following the structure of the official quickstart and restricting tools to read-only:
import asyncio
from google.antigravity import Agent, LocalAgentConfigfrom google.antigravity.types import BuiltinTools, CapabilitiesConfig
async def main(): config = LocalAgentConfig( capabilities=CapabilitiesConfig(enabled_tools=BuiltinTools.read_only()) ) async with Agent(config) as agent: response = await agent.chat("Which files are in the current directory? List only the file names.") print(await response.text())
if __name__ == "__main__": asyncio.run(main())Starting material: an empty directory containing only two or three fictional text files, for example notes-a.txt and notes-b.txt. Expected output: the terminal prints those file names, and the directory contents do not change. How to verify: run ls -l once before and once after, and confirm no files were added or removed and no modification times changed.
The names used in the example come from the official pages: Agent, LocalAgentConfig, agent.chat(...), await response.text(), CapabilitiesConfig, and BuiltinTools.read_only(). The official pages only say that BuiltinTools.read_only() restricts the agent to read-only tools; they do not list which tools it includes or whether it includes web tools. Confirm this in the SDK reference or source before granting more permissions.
Authentication
Section titled “Authentication”There are two paths, and neither should put a key in the script:
- Gemini API: set the environment variable
GEMINI_API_KEY. For key handling, see API key safety. - Gemini Enterprise (Vertex): pass
vertex=TrueinLocalAgentConfigand provideprojectandlocation; alternatively use the environment variablesGOOGLE_GENAI_USE_VERTEXAI,GOOGLE_CLOUD_PROJECT, andGOOGLE_CLOUD_LOCATION, and rungcloud auth application-default login. The official page says this path routes requests throughaiplatform.googleapis.comand Google Cloud credentials.
For the trade-offs between the two service surfaces, see Choosing between Google AI Studio and Gemini Enterprise Agent Platform.
Tools and default boundaries
Section titled “Tools and default boundaries”First, tell three kinds of things apart:
- Built-in tools: identified by the
BuiltinToolsenum ingoogle.antigravity.types. They include read (list_directory,search_directory,find_file,view_file), write (create_file,edit_file), execute (run_command), web (search_web,read_url_content),ask_question,start_subagent,generate_image, andfinish. - Custom Python functions: put them in
LocalAgentConfig(tools=[...]). They need type annotations and docstrings, which the agent uses to understand what each function is for. - Skills: use
skills_pathsto point to a directory containingSKILL.md.
Defaults the official pages mention:
- Tools page: web search (
search_web) and URL reading (read_url_content) are enabled by default; that page does not list other defaults. - Policies page: custom Python functions and standard read-only tools are allowed by default; high-risk operations such as
run_commandrequire explicit permission or a policy rule. - Overview page: it does not state default tools, default permissions, or an approval flow, and only links to the tools and policies pages.
From this, the default boundary is not the same as “minimal”: the web tools are on by default. Minimize the tools you give the agent for the task, then tighten further with enabled_tools or disabled_tools.
Policy syntax (from the policies page):
from google.antigravity import LocalAgentConfigfrom google.antigravity.hooks import policy
policies = [ policy.deny("*"), # Deny all tools first policy.allow("view_file"), # Allow only reading files policy.ask_user("run_command", handler=my_handler), # Running commands needs human approval]config = LocalAgentConfig(policies=policies)Key points: allow, deny, and ask_user all take a tool name as the argument, and deny("*") matches all tools; the handler of ask_user is an async function that receives the tool call, and returning True means approval. There is also policy.safe_defaults(handler=...), which allows read-only tools and asks before writing files, editing, and executing. google.antigravity.utils.interactive provides run_interactive_loop(config), which prompts “Allow execution? (y/n) [n]:” in the terminal; pressing Enter denies.
The official policies page does not state the matching order when several rules match at once. The example puts deny-all first, but it does not confirm whether order matters. Do not infer precedence from the example; run a test against a read-only directory where you expect a denial before you rely on it.
Subagents (entry point)
Section titled “Subagents (entry point)”Subagents let the main agent hand sub-tasks to separate context windows. The SDK has two kinds:
- Dynamic self-clones:
LocalAgentConfig(capabilities=types.CapabilitiesConfig(enable_subagents=True)); the official page says they inherit the main agent’s permissions and toolset. - Static custom: define them with
types.SubagentConfig(name,description,system_instructions,tools) and put them in the parent configuration’ssubagentslist; any custom tools assigned to a subagent must also be registered in the parent’stools.
Inheriting permissions means the wider the main agent is, the wider its subagents are. Narrow the main agent first, then enable subagents. For a full example, see examples/getting_started/subagents.py in the official antigravity-sdk-python repository.
Structured output
Section titled “Structured output”To make results parseable by a program, pass a Pydantic model class to LocalAgentConfig(response_schema=...), then call await response.structured_output() on the response. The official example uses the fields summary: str and action_items: list[str], and reads values with data["action_items"].
The official page does not say whether a dictionary or a model instance is returned, and it does not say what happens when the output does not match the schema. Do not skip your own checks: whether the fields are complete and the values are reasonable; see Structured Output.
Counterexamples and rewrites
Section titled “Counterexamples and rewrites”Counterexample one: writing the key into the script.
# Expected to fail: do not do thisAPI_KEY = "AIza...real key..."The key travels with the script into the repository, logs, and screenshots. Rewrite: keep the key out of the script and supply it through the environment variable GEMINI_API_KEY; in the repository, keep only fake values such as YOUR_API_KEY in something like .env.example, and add the real file to the ignore list. If it has already been committed, treat it as leaked, revoke it in the console, and generate a new one.
Counterexample two: giving unrestricted tools.
# Expected to fail: do not configure an untrusted directory like thisconfig = LocalAgentConfig() # Keeps the defaults, and the task is described as "fix all the problems"By default the web tools are on, command execution relies on policy as a backstop, and the task has no boundary. Rewrite:
- Start with
enabled_tools=BuiltinTools.read_only()and verify in a synthetic directory; - When writing is needed, use policies to set
ask_useroncreate_fileandedit_file, and confine the agent to a dedicated working directory; - When
run_commandis needed, approve it separately and show the full command each time; - Break the task into one concrete, verifiable step instead of “fix all the problems”.
Verification checklist
Section titled “Verification checklist”- Dependencies are installed in a fresh virtual environment, and
pip show google-antigravitydisplays package information; - No real key can be found in the script or the repository;
GEMINI_API_KEYexists only in the environment; - The minimal example was run in a synthetic directory, and the directory is identical before and after;
- You deliberately had the agent try to write a file or run a command, and confirmed it was denied or sent to approval rather than silently executed;
- You know whether the web tools are available: either explicitly disabled, or confirmed as needed by the task;
- If subagents are used, you confirmed the tools they receive do not exceed what you expect;
- If structured output is used, there is an independent check for field completeness and reasonable values.
Failure recovery
Section titled “Failure recovery”- Authentication fails: first check whether the current shell has
GEMINI_API_KEY(do not print its value); when using Vertex, checkproject,location,gcloud auth application-default login, and whetheraiplatform.googleapis.comis enabled for that project. - Import errors: confirm the package name is
google-antigravityand the import path isgoogle.antigravity; defer to the documentation for the installed version. - The agent did something it should not have: stop the process immediately, inspect the working directory with
git statusandgit diff, and restore from version control. For this reason, the first run should be in a repository with a clean commit or in a disposable directory. - A tool is denied: this means the policy is working; go back to the configuration, narrow the task or add an explicit
allow, and do not simply switch to allowing everything. - Suspected key leak: revoke it, regenerate it, and clean up history and logs.
The official example scripts are in the examples/getting_started/ directory of the antigravity-sdk-python repository, including policies.py, human_in_the_loop.py, and custom_tools.py, and can serve as a reference for actual behavior. The official site also has pages on Personas, MCP, local models, lifecycle, and hooks; this page did not open them, so read them yourself before use.
Next steps: if you are unsure which entry point to start with, read Choosing an Antigravity surface; for key handling, read API key safety; to make output consumable by programs, read Structured Output.