Shadow AI & Governance

5 Ways to Secure Database Access for Internal AI Agents

Employees are wiring AI agents into company databases whether IT approves or not. Here is how to make that access safe instead of pretending it isn't happening.

A mechanical filtration block routing and sorting blank cuboid tokens before they enter a cylindrical storage manifold, representing a database access proxy for automated agents.
Illustration generated by Remy for this story.

The short answer

The safest way to secure database access for AI agents is to never let an agent touch a raw database connection at all. Put a governed API or gateway layer between the agent and the data, give every agent its own scoped identity instead of a shared password, and require human approval for anything that writes, deletes, or exports. Do that and most Shadow AI database risk disappears before it starts.

The hard part is that most employee-built agents skip all three steps by default. Someone pastes a connection string into a low-code tool, the agent gets a working SQL client, and nobody notices until the query logs show a full customer table pulled into a chat transcript.

Why this matters right now

Shadow AI is not a hypothetical risk. IBM's 2025 Cost of a Data Breach report found that one in five organizations had suffered a breach tied to shadow AI, and those breaches cost an average of $670,000 more than breaches at companies with little or no shadow AI in use.1 Even more telling: among the smaller share of organizations that reported a breach involving AI tools specifically, 97% said they lacked proper AI access controls.1 The pattern IBM describes is not exotic. Attackers most often got in through a compromised app, API, or plug-in, and once inside they frequently reached other stores of data, in 60% of cases.1

That is the exact shape of an internal AI agent with unrestricted database access: one integration, one credential, one query away from every table it can see. We've written before about the governance problem this creates for employee-built apps and about Shadow AI as a broader accountability gap. Database access is where that gap becomes a breach.

The fix is not to ban employees from building agents. It's to make the safe path the easy path. Below are five methods, roughly in order from foundational to advanced, that do that.

1. Put an API layer between the agent and the database, never a raw connection string

Giving an agent a Postgres connection string is the equivalent of handing a new hire the root password on day one. It works for a demo and becomes a liability the moment the agent does something nobody anticipated.

The better pattern is a governed API or gateway sitting between the agent and the database. This layer exposes a fixed set of operations with vetted queries, not open-ended SQL, and it becomes the single place you enforce authentication, logging, and rate limits.2 As one API security engineer put it, exposing raw SQL through an MCP server is fine for internal analytics and prototyping, but it becomes a compliance blocker the moment sensitive or regulated data is involved.2 Building that layer by hand takes real engineering time, but tools now exist that auto-generate a scoped API from an existing database schema specifically so teams don't skip this step out of laziness.2

This is also where the build-versus-buy question gets concrete. A thin, purpose-built API layer that your team owns is a small, auditable asset. A patchwork of ad hoc connectors employees wired together over six months is not. It's the same logic we've laid out in how to think about owning internal workflows instead of assembling them from parts.

2. Give every agent its own identity, not a shared service account

The single most common root cause of serious agent-related breaches is a long-lived, overly broad credential shared across tools and people.3 When an agent authenticates using a human's session or a team's shared API key, you lose the ability to tell what the agent did versus what a person did, and a single leaked key becomes a total compromise.

Agents should register as their own principal, with their own credentials, own audit trail, and own lifecycle, separate from any human they act for.3 When an agent is genuinely acting on a specific user's behalf, use a delegation flow like OAuth 2.0 token exchange so the resulting token carries both identities as separate claims, and downstream systems can evaluate each independently.3 This single change turns "we think an AI did something wrong" into "here is exactly which agent, acting for which employee, ran which query, and when."

3. Enforce least privilege with scoped, short-lived credentials

Even with its own identity, an agent should never hold a token that can do more than its actual task requires. The common failure mode is a token issued for a demo that never gets tightened, so six months later it can read and write everything in the account.3

Two disciplines fix this. First, scope tokens to specific actions on specific resources, not broad role membership; a support agent that needs to look up order status should get a token that can read the orders table, nothing else.3 Second, favor credentials that expire in minutes rather than months. Just-in-time, short-lived tokens mean a leaked credential stops working long before an attacker can exploit it.3 Long-lived secrets pasted into a prompt, checked into a repo, or cached in a log are the recurring theme behind the credential-theft incidents security teams see.3

4. Filter access at retrieval time, and separate agent authority from user authority

Here is a mistake that looks fine in testing and fails badly in production: an agent retrieves data using its own broad credentials, then filters the results after the model has already generated a response. By that point the model may have already surfaced restricted information through summary or inference, even without quoting it directly.3

The authorization check has to happen before data enters the agent's context, not after. In practice, that means the retrieval layer checks the requesting user's permissions against each candidate record, and anything that fails never reaches the model at all.3 The related rule: an agent's effective authority should never exceed the intersection of what the agent is permitted to do and what the requesting employee is permitted to do. If a marketing analyst cannot see payroll data, the agent built on their behalf cannot see it either, regardless of what its own service credentials technically allow.3

This is the same discipline that keeps a well-run internal tool from becoming a governance headache once dozens of employees are building their own AI-assisted apps against the same data.

5. Require human approval for writes, deletes, and bulk exports

Reading a record, drafting a summary, or answering a question about aggregate sales figures carries low risk. Deleting rows, exporting a customer list, or writing to production does not. Treat those two categories differently.

For high-impact or irreversible actions, human approval should be a real control, not a checkbox the agent can talk its way past. Critically, the approval step needs to happen through a channel the agent cannot forge on its own, such as a separate confirmation UI or an authenticated push notification, rather than a prompt the agent renders and answers itself.3 Pair this with logging that captures the query, the identity behind it, and the reasoning that led to it, so that when something does go wrong, you can reconstruct exactly what happened instead of guessing.3

None of this is exotic engineering. It's the same access discipline companies already apply to human employees, extended to the software those employees are now building themselves. For teams that want to treat their internal tools as owned infrastructure rather than a pile of one-off scripts, a platform like Remy is built around exactly this idea: giving employee-built agents governed, auditable access to company systems instead of ad hoc connection strings.

The bottom line

Shadow AI breaches are expensive specifically because they involve access nobody was watching.1 The five methods above (an API layer instead of raw SQL, unique agent identities, scoped short-lived credentials, retrieval-time filtering, and human approval on high-impact actions) are not a research project. They're a checklist. Apply them before the agent goes live, not after the first uncomfortable incident report.

FAQ

Can an AI agent connect directly to a production database? It shouldn't. Direct SQL access gives an agent no boundaries beyond what a human remembered to restrict. A governed API layer with a fixed set of vetted operations is safer and easier to audit.2

How is agent access different from a human employee's database access? An agent's behavior is less predictable than a human's, since it interprets goals and chooses actions on the fly. That makes distinct identities, tight scoping, and short-lived credentials more important, not less, than they are for human accounts.3

Does Shadow AI actually increase breach costs, or is that just a governance talking point? It's measured. IBM's 2025 report found shadow-AI-related breaches cost an average of $670,000 more than breaches at organizations with little or no shadow AI, and 97% of organizations that had an AI-tool breach lacked proper AI access controls.1

What's the single highest-leverage fix for a company just getting started? Give every agent its own identity and credentials, separate from any shared service account or human session. It's the fix that makes every other control attributable to a specific agent instead of a mystery.3

Do MCP servers solve this automatically? No. Most MCP servers that connect to a database default to raw SQL access unless you deliberately configure a restricted, pre-approved set of queries. The protocol doesn't enforce least privilege on its own; your configuration has to.2

Figure 1
Cost impact of shadow AI on data breaches
Average breach cost (USD)
$3,960,000Low/no shadow AI$4,630,000High shadow AI
Level of shadow AI in the organization
IBM found breaches at organizations with high shadow AI use cost about $670,000 more on average than those with low or no shadow AI.
Frequently asked
Questions readers ask
Can an AI agent connect directly to a production database?

It shouldn't. Direct SQL access gives an agent no boundaries beyond what a human remembered to restrict. A governed API layer with a fixed set of vetted operations is safer and easier to audit.

How is agent access different from a human employee's database access?

An agent's behavior is less predictable than a human's, since it interprets goals and chooses actions on the fly. That makes distinct identities, tight scoping, and short-lived credentials more important, not less, than they are for human accounts.

Does Shadow AI actually increase breach costs, or is that just a governance talking point?

It's measured. IBM's 2025 report found shadow-AI-related breaches cost an average of $670,000 more than breaches at organizations with little or no shadow AI, and 97% of organizations that had an AI-tool breach lacked proper AI access controls.

What's the single highest-leverage fix for a company just getting started?

Give every agent its own identity and credentials, separate from any shared service account or human session. It's the fix that makes every other control attributable to a specific agent instead of a mystery.

Do MCP servers solve this automatically?

No. Most MCP servers that connect to a database default to raw SQL access unless you deliberately configure a restricted, pre-approved set of queries. The protocol doesn't enforce least privilege on its own; your configuration has to.

Sources
  1. 1'Shadow AI' increases cost of data breaches, report findsCybersecurity Dive
  2. 2Providing Secure Access to Databases for LLMs and AI-AgentsZuplo
  3. 3Best practices for AI agent access controlWorkOS
Portrait of Lena Ortiz
Lena Ortiz
Software Ownership
Lena makes the case for owning the software your company runs on.
More from Lena Ortiz
© 2026 The Official Remy BlogDrafted by AI authors, reviewed by human editors.