ANTIGRAVITY LABJP
Articles/Antigravity Basics
Antigravity Basics/2026-06-16Advanced

Collecting Guardrails Across Projects Into One Place — A Thin Wrapper Around the Antigravity SDK

When you copy the same safeguards into every project, you eventually fix one and leave the other stale. Here is a design that builds a single thin wrapper around the Antigravity SDK to centralize cost caps, allowed tools, and output validation — from someone running several apps in parallel.

antigravity361SDK2guardrails4design6operations11TypeScript10reuse

Premium Article

It started when an agent in one project wrote a file into a directory it was never supposed to touch. Tracing it back, the allowed-tools restriction I had set in another project simply was not present in this one. As I copied the same safeguards from project to project, one place had been left behind, still stale.

As an indie developer running several apps and several sites in parallel, the code that calls the Antigravity SDK scatters everywhere. Release automation for the App Store and Google Play, AdMob report rollups, article generation — I hand all of it to agents. And scattered code always drifts apart, bit by bit. Fix one place and forget another. When migrating to a new model, you fix three call sites and miss the fourth. Carefulness alone could not prevent that drift.

So I stopped calling the SDK directly. I built exactly one thin wrapper and routed every project through it. Here I share the design that collected cost caps, allowed tools, and output validation into that wrapper.

Why a "thin" wrapper

The first thing I watched was not making the wrapper too thick. Build a heavy abstraction that re-wraps every SDK feature, and the wrapper has to chase every SDK update, which only increases maintenance.

What I aimed for was a thin layer that passes SDK calls through almost as-is and only injects the cross-cutting safeguards I want applied everywhere. Concretely: create a single point that every call must pass through, and check cost, tools, and output there. Do not hide the SDK's own API; only forbid the dangerous defaults. That line is the condition for a wrapper that lasts.

The cross-cutting safeguards I wanted to collect came down to three.

  1. Cost caps. Structurally forbid runs with no cap, and stop on both the estimate and the actual cost.
  2. Allowed tools. By default permit only read operations; do not let writes through without explicit permission.
  3. Output validation. Do not adopt output that fails the schema, and keep it out of the production downstream.

These three are gotchas I want enforced identically in every project. That is exactly why collecting them in one place — rather than copying them around — was worth it.

Forbid dangerous defaults with types

Half the value of the wrapper actually lives in the type design. Call the SDK directly and the safeguard arguments are "optional." Optional means forgettable. In the wrapper, I made the must-not-forget arguments required.

import { createAgent, type AgentRunResult } from "@antigravity/sdk";
 
// Safeguards every call must pass — all required
interface SafeRunOptions {
  task: string;
  // Do not make the cost cap optional. Forbid uncapped runs at the type level
  maxCostUsd: number;
  // Allowed tools must be explicit. An empty array means "permit nothing"
  allowedTools: string[];
  // Output schema validation is required. No adopting output without it
  validate: (output: unknown) => boolean;
  // Receive the model as a pinned version, not an alias
  model: `gemini-3.5-flash-${string}` | `gemini-3.5-pro-${string}`;
}
 
export async function safeRun(opts: SafeRunOptions): Promise<AgentRunResult> {
  // This is the single point every call passes through; later sections add guards
  return runWithGuards(opts);
}

Not making maxCostUsd optional paid off. In the SDK, omit the cap and it runs unbounded. Make it required in the wrapper's type, and code that forgets the cap will not even compile. You move safeguards from "verify by eye that it is written" to "it will not build unless you write it."

Constraining model to a pinned version with a template-literal type follows the same idea. Code that passes only the alias gemini-3.5-flash becomes a type error, forcing every call to be written with a version.

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
Get the overall design for routing every call through one thin wrapper so cost caps, allowed tools, and output validation live in a single place
Learn a type design that forces required arguments and forbids dangerous defaults, plus the fail-closed implementation (TypeScript) that paid off in production
See the operating rules that consolidated safeguards scattered across five projects into one wrapper and drove policy-update misses to zero
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

Antigravity2026-05-31
Keeping Agent Behavior Consistent Across Separate Repositories: Notes on Multi-Repo Governance
How to keep Antigravity agents behaving consistently across several independent repositories when a monorepo isn't an option. A layered governance design with a working distribution script and drift audit, drawn from running four sites in parallel.
Antigravity2026-06-16
When Your Agent Got 4x Faster: Rebuilding the Parallel Pipeline
When the Antigravity CLI moves to a faster model, the bottleneck in your parallel agent pipeline shifts. Here is a practical way to rethink verification, task granularity, concurrency, and cost caps with speed as the new baseline.
Antigravity2026-06-15
Matching Antigravity 2.0's Three Layers to Development Phases: Explore, Iterate, Operate
How I assign Antigravity 2.0's desktop, CLI, and SDK to development phases instead of features, with concrete handoff patterns between layers and the production pitfalls I hit.
📚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 →