ANTIGRAVITY LABJP
Articles/Agents & Manager
Agents & Manager/2026-06-15Advanced

Treating the Managed Agent as a Cost-Capped Throwaway Worker: Isolating Untrusted Input from Production

How to use the Managed Antigravity Agent, now in Gemini API public preview, as a throwaway worker that is born and discarded per request. Cost caps, isolation, and idempotency with implementation steps.

antigravity355managed-agent2gemini-api6agent-design4cost-control3

Premium Article

A Managed Agent called antigravity-preview-05-2026 has reached public preview in the Gemini API. Inside a sandbox it can plan, reason, run code, manipulate files, and even browse the web autonomously. When I first tried it, I reached for it as a "resident partner I could hand anything to" — and quickly changed my mind. Keeping it resident meant cost, permissions, and state all crept up bit by bit until they became unmanageable.

What I switched to was using it so that it is born for one request and discarded once it returns a result. Not a persistent assistant but a throwaway worker. Once I framed it that way, the Managed Agent actually became easier to handle. Here is why throwaway suits it, and how to implement it.

Why "throwaway" suits untrusted input

The appeal of the Managed Agent is that it runs in a sandbox isolated from your own environment. That means it is ideal for processing untrusted external input.

Summarizing the contents of a URL a user sent you, reshaping JSON of unknown provenance pulled from an external API — running these directly in your own production environment is frightening. Hand them to a throwaway worker running in a sandbox, and whatever happens stays one-off, leaving no trace in production.

Conversely, keeping it resident instead of throwaway raises the concern that state from the previous request leaks into the next. The more you handle untrusted input, the more being stateless acts as a safety device. I try to see this statelessness not as a feature limitation but as a design advantage.

Confine the cap to one request

The crux of a throwaway worker is always attaching a cost and time ceiling to each launch. With a resident agent, adding caps after the fact is hard; with throwaway you can state them explicitly on every launch.

from google import genai
 
client = genai.Client()
 
def run_ephemeral(task_prompt: str, untrusted_input: str) -> dict:
    # 1 request = 1 worker. Drop the reference when done
    resp = client.agents.run(
        model="antigravity-preview-05-2026",
        instructions=task_prompt,
        input=untrusted_input,
        config={
            "max_cost_usd": 0.20,   # ceiling this worker may spend
            "timeout_s": 120,        # stop runaways by time
            "tools": ["web_fetch"],  # hand over only the tools needed
            "sandbox": "isolated",   # cut off access to production files
        },
    )
    return {"ok": resp.status == "completed", "output": resp.output}

What works here is the two-stage guard of max_cost_usd and timeout_s. The cost cap stops token runaways; the timeout stops infinite loops and stuck waiting states. In my operation, before I attached these two there were a few requests a month that cost several times what I expected; after adding the caps, that went to zero.

Narrowing tools to only what's needed matters too. There's no reason to hand file-write access to a worker that only fetches the web. Don't hand it over, and even if the instructions get hijacked the damage doesn't spread.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
An implementation pattern for a throwaway worker that is discarded after a single run
How to confine a cost cap, timeout, and least privilege to one request
An idempotent intake flow that isolates untrusted input and keeps production clean
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

Agents & Manager2026-06-15
Calling a Managed Antigravity Agent from the Gemini API: Design Notes on the Preview Model
antigravity-preview-05-2026, now in public preview on the Gemini API, is a Managed Agent that plans, runs code, edits files, and browses the web autonomously inside a sandbox. Here is how it differs from rolling your own orchestration, and where to draw the line.
Agents & Manager2026-06-01
Capping Parallel Agents With a Token Budget — Designing a Guard That Stops Runaway Cost
Running many agents in parallel quietly inflates your token bill. This is not about shrinking prompts — it is about a governance layer that meters spend in real time and cuts it off at a budget. Full design and TypeScript implementation, drawn from running six sites autonomously.
Agents & Manager2026-06-15
Containing Failure in Antigravity Multi-Agent Systems: Three Boundaries That Stop Cascades
Antigravity multi-agent setups run beautifully in isolation but cascade in production, where one small failure drags the whole orchestration down. These notes organize the fix around three boundaries—layered control, trust separation, and observability with idempotency—down to the TOML and the correlation-ID wrapper.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →