The Nightmare Scenario: AI Agents with Production Credentials

AI agents are increasingly running with direct access to production databases, APIs and file systems. The risk is not theoretical. A slight hallucination, a misinterpreted prompt, or an unconstrained recursive task can lead an agent to drop a critical table to “optimize space,” alter a database schema mid-operation, create hundreds of thousands of records before anyone notices, or expose sensitive data in ways nobody intended. The agent doesn’t malfunction. It follows its internal logic to a conclusion that made sense from its perspective. The problem is that there was nothing between that logic and your production system.

Why traditional IAM isn’t enough

Traditional access control was built for human users. It assumes the actor understands the consequences of what they’re doing, and that they operate at human speed — slowly enough for others to observe and intervene. Neither assumption holds for AI agents. An agent executes at machine speed. It has no felt understanding of the difference between a reversible operation and a permanent one. And it will optimize toward its goal until something stops it.

What’s needed is a control layer built around three dimensions that traditional IAM doesn’t address.

Operation irreversibility. Not all operations are equivalent. Reading is always safe. Creating can usually be undone. Dropping a table is permanent. The control model needs to treat these as categorically different — not just different permission levels, but different enforcement mechanisms. A hard block on DROP that never reaches the database is fundamentally different from a permission check that can theoretically be overridden.

At the implementation level this means classifying every operation at the gateway before forwarding. The classification is not just SELECT vs DELETE — it maps to a risk tier:

This classification is enforced at the gateway layer, not at the database permission level. The reason: database permissions can be bypassed if credentials are leaked or misconfigured. The gateway is the only path — the database has no direct network exposure to the agent at all.

Blast radius. The question isn’t only “is this operation permitted” but “how much can this agent affect in this session?” An agent permitted to create records can still cause a catastrophic outcome if it creates 200,000 of them. Volume limits per session — with automatic pausing and human confirmation required to proceed — address this independently of per-operation permissions.

In practice this means maintaining a session counter per agent identity. Every INSERT, UPDATE and DELETE increments the counter. When the counter crosses a configurable threshold — 1,000 rows affected for production environments, 10,000 for staging — the gateway pauses execution, holds the pending operation, and fires a notification to the human operator. The operation does not fail — it waits. If the operator confirms within the timeout window, execution resumes. If they don’t, the session is terminated and the pending operation is discarded.

The threshold is configurable per environment, per agent type and per table. A data migration agent operating on a staging database has a higher threshold than a coding assistant operating on a production system.

Execution velocity. When humans perform operations, other humans have time to observe and intervene. Machine-speed execution removes that window entirely. Velocity limits restore it: not preventing operations, but pacing them so a human can watch what’s happening and interrupt if needed.

This is implemented as a token bucket rate limiter at the gateway, with separate buckets per operation class. Write operations are throttled to a configurable maximum per second — typically 10–50 ops/sec for production environments. Read operations are not throttled by default but are logged. The rate limiter is applied after the operation classification step, so a hard-blocked DROP never reaches the rate limiter at all.

What the gateway looks like in practice

The AI Agent Access Control Gateway sits between every agent and every system it touches. Agents hold no direct credentials to databases, APIs or file systems. All operations go through the gateway.

Architecturally, the gateway runs as a sidecar proxy or a standalone service depending on deployment model. For database access it operates as a SQL proxy — the agent connects to the gateway on a standard PostgreSQL or MySQL port, and the gateway forwards permitted queries to the actual database. The agent’s connection string points at the gateway; it never has the actual database credentials. For API access the gateway operates as an HTTP proxy with request inspection. For file system access it operates as an NFS or S3-compatible endpoint with policy enforcement.

Each agent session is initiated with a declared scope — a structured manifest that specifies the task context, the intended operations and the affected resources. The gateway validates the declared scope against the agent’s policy profile and locks the session to that scope. Operations that fall outside the declared scope are blocked even if they would otherwise be permitted — an agent that declared “I am refactoring the frontend” cannot access the payments table even if the payments table is generally accessible to agents of this type.

Object visibility is filtered at the schema level before the agent receives any response. An agent assigned to front-end refactoring issues SELECT table_name FROM information_schema.tables and receives a list that excludes payments, user_credentials and audit_logs entirely. They do not appear as forbidden — they do not appear at all. This schema-level filtering is applied to every introspection query, every ORM model discovery call and every API endpoint enumeration. The most effective protection is invisibility.

Each operation is evaluated against a policy set:

  • Read operations pass through freely after scope validation and visibility filtering
  • Creates are rate-limited and tracked against the blast radius counter
  • Updates require dry-run output — the gateway executes an EXPLAIN or equivalent, returns the plan to the agent, and requires an explicit proceed signal before executing
  • Soft deletes enter a reversibility queue with a configurable delay (60 seconds by default), during which a webhook fires to the configured notification channel and a human can cancel
  • Hard deletes, drops, truncates and schema changes are blocked at the gateway and never reach the underlying system
  • Backups are out of scope for all agents by default — backup directories and snapshot APIs are not present in the agent’s visibility layer regardless of policy

Every action — attempted, permitted, blocked, queued or approved — is written to an immutable append-only audit log. The log is physically separate from the systems the agent can access and is written via a one-way pipeline the agent has no credentials for. Each log entry captures: agent identity and session ID, declared scope, actual operation text, classification result, policy decision, timestamp, and — for blocked or queued operations — the notification reference. This log is the foundation for incident reconstruction, compliance reporting and, eventually, supervised fine-tuning of agent behaviour on domain-specific safety constraints.

Notification and approval flow

For operations that enter the reversibility queue or trigger blast radius alerts, the gateway fires a structured webhook to the configured notification endpoint — typically Slack, PagerDuty or a custom dashboard. The payload includes the operation text, the agent identity, the session context and a signed cancel token valid for the queue timeout window.

The human operator receives a message that shows exactly what the agent is about to do, in plain language and in the raw operation text. They can cancel with a single action — clicking a link that submits the cancel token — or do nothing, in which case the operation executes when the timeout expires.

For schema changes and migrations, the approval flow is out-of-band by design: the gateway does not queue these operations with a timeout, it requires an explicit approval from a designated approver through a separate channel before the operation is even forwarded to the queue. This prevents the failure mode where a timeout expires during an on-call gap and a schema migration executes unreviewed.

This is not a solved problem but it is a solved practice

Purpose-built access control for AI agents doesn’t exist as a mature product today. Secrets management tools like Vault address credential exposure but not operation policies. Database access controls address permissions but not velocity or blast radius. OS-level sandboxing addresses file system access but not database operations or API calls. Service mesh tools address network-level access but not semantic operation classification.

What’s needed is a layer that treats AI agents as a distinct principal type — not human users with elevated permissions, not service accounts with fixed scopes, but autonomous agents with variable task contexts, machine-speed execution, and no intrinsic understanding of consequence. The principal model needs to encode not just identity but declared intent, and enforce that the session stays within the declared intent regardless of where the agent’s reasoning leads.

At Sofycod, this layer is not optional. Every AI system we build that involves agent access to data — whether a custom BMS, an agentic pipeline or an AI engineering team working inside a client’s infrastructure — includes an access control layer designed around these three principles: operation irreversibility, blast radius and execution velocity. It is implemented as a standard architectural component, configured per environment and per agent type, and included in the delivery documentation so the client’s team can operate and extend it after handover.

It is not an add-on requested after something goes wrong. If you are building AI agents that touch production data and this layer isn’t in your architecture yet, that is the conversation we should be having.

If you need help: contact me via SOFYCOD corporate web site Contact Author, and I can consult with you and help to build necessary architecture.

Categories: