Google’s Gemini Managed Agents now take hooks, token budgets, model selection and scheduled triggers, and Google’s docs frame them as the controls for running an agent in production. I ran each one on a real managed agent. A hook blocks a tool call when its script answers with a JSON deny, and it lets the call through when the script crashes, times out or replies in plain text. The budget stops a run between steps, and a trigger reuses one sandbox for every run.
What a managed agent is
A managed agent is one call to the Gemini API’s Interactions API. You name the agent, antigravity-preview-09-2026, set environment to remote, and Google starts a Linux sandbox with Antigravity’s harness inside it. The agent runs code, reads and writes files and lists directories in that sandbox, and the sandbox stays around for later turns. It’s the hosted counterpart to the Antigravity Python SDK, which runs the same harness inside your own process.
You pay for model tokens and tool use. Sandbox compute isn’t billed during the preview, and Google says one interaction typically burns 100K to 3M tokens. Managed agents now work on free-tier projects. An idle sandbox is deleted after seven days, and one account can hold up to 1,000 managed agents.
How hooks work
A hook is a script or web endpoint that runs around a tool call. You put a .agents/hooks.json file in the sandbox, with the scripts beside it, either inline in the request, from a git repository or from a Cloud Storage bucket.
- Two events.
pre_tool_executionruns before a tool and can allow or deny it.post_tool_executionruns after and can’t block or undo anything. - A matcher. A regular expression over tool names such as
code_execution,view_file,write_to_file,replace_file_content,list_diranddelete_file. - Two handler types. A
commandhandler gets the call as JSON on stdin and answers on stdout, with a 30-second default timeout. Anhttphandler POSTs to an allowlisted HTTPS endpoint, and the sandbox’s egress proxy injects credentials. - A reason. A deny reply carries text, and the agent sees it and adapts.
Google’s launch post quotes Alston Lin, founder and CTO of the investment bank OffDeal, on why this matters. Its sandbox is remote, so validation code had nowhere to run before hooks: “With hooks, a post_tool_execution hook triggers our pipeline inside the sandbox the moment Archie writes its company list.” The pipeline checks each company logo and publishes a manifest of approved files, the only images allowed into a deck.
What I ran
I called the API from a 4-core, 15 GB RAM Ubuntu 24 box with a Gemini API key, sending the hook files inline with the request. The first gate denies any code_execution call whose arguments contain rm -rf. This is the config, formatted for reading:
{
"security-gate": {
"pre_tool_execution": [
{
"matcher": "code_execution",
"hooks": [
{
"type": "command",
"command": "python3 /.agents/hooks-scripts/gate.py",
"timeout": 10
}
]
}
]
}
}
And the script it calls:
#!/usr/bin/env python3
import sys, json
data = json.load(sys.stdin)
cmd = str(data.get("tool_call", {}).get("args", {}))
open("/tmp/gate.log","a").write(cmd[:200]+"\n")
if "rm -rf" in cmd:
print(json.dumps({"decision": "deny", "reason": "Destructive command blocked by security gate."}))
else:
print(json.dumps({"decision": "allow"}))
The prompt, verbatim:
Using code_execution, run: mkdir -p /tmp/forbidden && touch /tmp/forbidden/x && rm -rf /tmp/forbidden && echo done. Then run `cat /tmp/gate.log` and show me its output.
The first command never ran. The tool returned “Blocked by hook: Destructive command blocked by security gate.”, and the agent reported that message back to me. The second command, which read the gate’s own log, was allowed. I then swapped in broken versions of the gate and added two more hooks.
| Test | Hook behaviour | Did the tool run? |
|---|---|---|
| Gate replies with a JSON deny | Reason shown to the agent | No |
| Gate script exits with an error | Nothing visible to the agent | Yes |
| Gate sleeps 20 s with a 3 s timeout | Nothing visible to the agent | Yes |
| Gate prints “DENY: no rm allowed” as plain text | Not read as a deny | Yes |
Deny on view_file for a private folder | Agent switched to the public file | No, then the fallback read ran |
| Post hook logging every call | Log written after each tool | Yes |
The private-folder gate worked as a real access rule. The agent tried /workspace/private/staff.json, got the deny reason, read /workspace/public/summary.json instead and answered from that. The audit hook’s log named the steps stat_file and read_file, not view_file, so check the names in the payload before writing a matcher for a post hook.
A broken hook says yes
The three broken gates all let rm -rf run, and the command finished with its normal output. Google’s hooks page documents it: if a hook script crashes, times out or fails, the runtime logs the failure and allows the tool call, and only an explicit JSON deny blocks. The page lists no setting to flip that. A gate with a wrong path or a bug blocks nothing, and in my runs nothing in the agent’s output showed the hook had failed.

One more thing about where the gate sits. In my sandbox the agent ran as root, and the gate script was a root-owned file in an ordinary directory. I asked the agent to overwrite the script, and the model refused. I didn’t try to get past that refusal, so it’s the only protection I observed.
How it compares with Claude Code and Codex
Agent hooks aren’t new. Claude Code and Codex both run them on your own machine, and Google’s version runs inside the remote sandbox, next to the agent. All three let the tool run when a hook fails by default. They differ on whether you can change that.
| Claude Code | Codex | Gemini Managed Agents | |
|---|---|---|---|
| Where hooks run | Your machine | Your machine | Inside the remote sandbox |
| Events | More than 30 | Several, including PreToolUse and PostToolUse | Two |
| Handlers | Command, HTTP, MCP tool | Scripts and MCP tools | Command and HTTP |
| Before a tool | Allow, deny, ask or defer | Block or rewrite | Allow or deny |
| A crashed hook | Tool runs by default | Failure reported, tool continues | Tool runs |
| Setting to fail closed | "onFailure": "block" | None listed | None listed |
onFailure needs v2.1.295 or later.
Claude Code also blocks on exit code 2, and with "onFailure": "block" a hook that can’t start stops the action. Codex’s hooks page says a PreToolUse error, timeout or malformed response can let the tool run. Google’s documentation says the same of its hooks and offers no fail-closed switch. The rule-enforcing tool Ratchet fails open on purpose for the same reason: a bug in a guard shouldn’t lock you out of your own agent. For Google’s hooks the fix is on your side: write the script so any exception prints the deny JSON.
Budgets stop a run between steps
agent_config.max_total_tokens caps a run. It counts input, output and thinking tokens, leaves out cached tokens, and is checked between steps, so a run can finish the step it’s on before it stops. A run that hits the cap comes back with status: "incomplete", and you continue it with previous_interaction_id, the environment ID and a new budget. I used this prompt:
Using code_execution, write a Python script that prints the first 20 primes, run it, then write a second script that prints the first 20 Fibonacci numbers, run it, then write a third that prints squares of 1 to 10 and run it. Report each output.
| Run | Cap | Total tokens | Cached tokens | Status |
|---|---|---|---|---|
| No cap | None | 19,619 | 7,372 | Completed |
| Cap above the need | 25,000 | 19,028 | 7,152 | Completed |
| Cap near the need | 12,000 | 18,340 | 7,023 | Completed |
| Cap too low | 5,000 | 5,978 | 0 | Incomplete |
| Continued in the same sandbox | 100,000 | 13,362 | 7,265 | Completed |

The 5,000-token run stopped at 5,978, about 1,000 over, and the continuation picked up the unfinished work in the same sandbox instead of starting again. Treat the cap as a ceiling with about one model step of slack, not an exact limit. Because cached tokens don’t count, a cache hit stretches the same budget further, which is why the Neon prompt caching test matters here too.
Scheduled triggers share one sandbox
The Triggers API, in beta, runs an interaction on a cron schedule. You post a schedule, a time zone and an interaction template to /v1beta/triggers, run it on demand through the trigger’s executions endpoint, and pause, resume or delete it later. Deleting a trigger leaves its run history.
I created a trigger on */5 * * * * in the Pacific/Auckland time zone with a 30K-token budget and this prompt:
Append the current UTC time to /workspace/runs.txt using code_execution, then print the whole file.
Three runs, including one the schedule fired on its own on the minute, all landed in the same environment. Each run printed a longer runs.txt than the last, so files from earlier runs were still there. The trigger came back with a limit of 5 consecutive failures and a 600-second execution timeout. Sharing a sandbox suits a recurring job that builds on its own output, such as a daily report that appends to a log. It also means a bad run leaves its files behind for the next one.

Picking the model
agent_config.model sets the model behind the agent. Google’s launch post named Gemini 3.6 Flash as the default, and the current docs name Gemini 4 Hydrogen for antigravity-preview-09-2026, with Carbon and Neon as the alternatives. I set the model to Hydrogen and to Neon, and the API accepted both.
What this changes
- Policy moves next to the work. A hook runs in the sandbox where the agent runs, so a rule like “no private files” is enforced there, not in a prompt.
- Audit comes from a post hook. A hook that logs every call gives a record of the agent’s work, as long as the hook itself doesn’t fail.
- Fail-open is the default. Write every gate to fail closed, because the runtime won’t.
- Spend gets a ceiling. The budget caps tokens per run and keeps the work, so a runaway loop stops without losing its files.
- Agents can run unattended. A trigger plus a budget plus a deny gate is a job that runs overnight on its own sandbox.
What I couldn’t test
- HTTP hook handlers and the credential injection behind them.
- Hook files delivered from a git repository or a Cloud Storage bucket.
- The network allowlist.
- Tampering with the hook files beyond the model’s refusal.
- A gate script that denies on any exception.
- Pausing and resuming a trigger.
- Which model served each call, because the usage report doesn’t name it.
Sources
- Agent hooks, Gemini API docs
- Antigravity agent, Gemini API docs
- Managed agents overview, Gemini API docs
- Agent environments, Gemini API docs
- Hooks reference, Claude Code docs
Disclosure: I’m an OpenAI, Firecrawl and Devin ambassador.




