◉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.

antigravity476managed-agentgemini-api8agent-design10cost-control5

✦ 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-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 my own overnight jobs.
◈ Agents & Manager2026-10-13
Turning Gut-Feeling Judgments into Rules an Agent Can Actually Follow
A repeatable way to turn the judgment calls that live only in your head into rules an Antigravity agent can apply: build conditions from past cases, choose where in .agents/rules they live and which trigger to use, catch rules that are silently ignored, and replay old cases before trusting them.
◈ Agents & Manager2026-09-04
Snapshot Your Agents' Effective Scope So You Notice the Day a Default Changes
Antigravity 1.1.25 made Markdown-defined custom agents inherit the surrounding skills, rules, and subagents by default. Here is the snapshot-and-diff routine I now use to check whether an agent I meant to keep narrow quietly got wider after an update.