All Insights
Database Security & GovernanceOctober 28, 2026 · Blueprint · 9 minBy Amit Parikh — Founder & Principal

Autonomous Agent Containment: Bridging the 23% Security Gap in PostgreSQL & Oracle

Defending enterprise database platforms against autonomous AI agent workloads — moving from reactive engine sandboxes to deterministic pre-execution AST governance.

Buyer Objection

While evaluating autonomous AI agents and local copilots interacting directly with core enterprise databases, engineering leadership often assumes a locked-down database account (SELECT-only grants, read-only transactions, and strict statement timeouts) is sufficient isolation. In practice, restricted roles leave metadata reconnaissance and unbounded cost-abuse paths wide open. The enterprise needed an empirical reference architecture to measure where native engine controls succeed and where pre-execution governance is required. Mode: light-touch, high-leverage evaluation.

Architecture Thesis

Traditional database permissions and engine sandboxes are necessary but incomplete. True agent containment requires a defense-in-depth architecture where a deterministic pre-execution Abstract Syntax Tree (AST) guard intercepts query structure at the gateway before it hits the socket, complementing native engine controls rather than replacing them.

Reference Architecture

Never let the query generator approve its own query

Layered runtime controls for agentic Text-to-SQL

LLM / Agent

Candidate query generator only. No broad privileges.

AST Policy Guard

Parse SQL (e.g. SQLGlot). Allow-list SELECT/WITH, reject DDL/DML, cap rows.

Entitlement & Predicate Checks

Agent identity, role, row-level entitlements, tenant predicates, cost/time limits.

Database Driver

Receives only queries that passed deterministic checks.

Database-Native Security

Least-privilege roles + Row-Level Security (PostgreSQL policies, Oracle VPD).

Application-layer checks complement database-native security. They don't replace it.

The gateway layer intercepts and parses query structure in ~135 µs before the request ever hits the socket. The session layer enforces least-privilege grants and read-only transaction boundaries. The engine layer bounds execution time, statement timeouts, and native safety controls. Every layer is exercised by the multi-engine test harness: a raw 44-vector adversarial suite run across PostgreSQL 18 and Oracle 23ai, so each containment claim is measured, not asserted.

Preconditions & Assumptions

  • Adversarial test suite standardized across 44 distinct vector classes (DML, DDL, schema sniffing, resource abuse).
  • Target engines deployed under identical restricted non-superuser roles (app_dev_restricted).
  • Performance baseline established for raw engine execution versus full-stack pre-driver parsing.

Control Model

  • AST policy rules carry deterministic matching; unparseable or ambiguous syntax defaults to rejection.
  • Engine timeouts and row limits retained as a secondary systemic safety net.
  • Query guard rules managed as version-controlled code rather than ad-hoc application logic.

Validation Plan

  • Vector interception rates measured across PostgreSQL 18 and Oracle 23ai; false positive/negative vectors reviewed against query syntax rules.
  • Parse latency overhead reconciled against raw query execution time.
  • Resource consumption (CPU/memory overhead on proxy layer) measured under simulated concurrency.

Quantified Outcomes & Methodology

91% Total Vector CoverageFull-stack defense (AST guard + engine sandbox) successfully intercepted 40 of 44 adversarial vectors, up from 77% (34/44) with engine sandboxes alone. Engagement-derived benchmark.
135–139 µs Parse OverheadDeterministic pre-driver AST inspection executed with minimal latency impact, ensuring security enforcement does not degrade transaction throughput. Engagement-derived benchmark.
Zero Structural Bypass for ReconnaissanceEliminated unauthorized catalog and metadata enumeration (pg_catalog, information_schema) that bypassed standard role-based grants. Engagement-derived benchmark.

All figures are empirical outcomes from the anonymized multi-engine benchmark harness described above — no external vendor marketing claims cited.

Scope & Methodology

Methodology: vector coverage and parse latency measured within controlled Docker workbench environments running PostgreSQL 18 and Oracle 23ai. External factors — custom client connection pooling, network hops, and complex ORM query generation — were observed but not controlled; results are empirical and harness-derived, not universal across every legacy schema.

Risks & Non-Goals

  • Pre-execution AST parsing does not replace database-level row security (RLS/VPD) or encryption.
  • Obfuscated dynamic SQL constructed entirely at runtime inside application code requires strict AST normalization.
  • Cost-abuse patterns (such as complex cross joins using allowed syntax) require execution-time resource limits alongside structural guards.

Rollout Approach

  • Stage 1: Deploy AST policy layer in observation / audit-only mode to log structural patterns without blocking live agent traffic.
  • Stage 2: Enforce blocking rules for high-risk schema reconnaissance and multi-statement injection vectors.
  • Stage 3: Integrate runtime cost guards and row-limit policies into the proxy tier after two quarters of measured concurrency tuning.

Executive Takeaway

Most effective when autonomous AI agents and local development copilots require rigorous guardrails against schema reconnaissance and query-based resource exhaustion without slowing down engineering velocity.

Continue the conversation

If this pattern matches a pursuit, let's sit the room.

Only used to send new blueprints. No sharing, ever.

Book a Strategy Call