# What permissions an AI coding agent should actually have in a database

> Least privilege, every security write-up agrees: a read-only role, never a superuser. The scope table most guides stop at listing, plus what Scribase enforces beyond it — expiry, no self-escalation, and SQL that never runs as a superuser even with a write token.

Source: https://scribase.com/ai-agent-database-permissions

Give an agent the smallest token that does the job, with an expiry, and revoke it when the work is done. That sentence is in every security write-up on connecting an agent to a database. The part that matters is what it looks like in a real scope table, and what still needs enforcing even inside a "write" scope.

## The consensus, and where it stops

Every roundup of Postgres MCP servers lands on the same advice: connect with a read-only role, never a superuser, especially for production. That advice is correct and incomplete — a coding agent that only ever queries is not doing its job. The real question is what a write-capable agent token should and should not be able to do, which is where most guides stop.

## A real scope table

_Scribase agent-token scopes_

| Scope | Grants |
| --- | --- |
| project:<id>:read | Read one project; project:*:read for every project |
| project:<id>:write | Change it: environments, auth, storage, functions invoke, secrets names |
| project:<id>:admin | Destructive changes on production, backups, restores, domains, key rotation |
| sql:read / sql:write | The SQL routes, read-only or read-write |
| migrations:write | Apply migrations |
| branches:write | Create, merge and delete branches and previews |
| keys:secret | The secret key, connection strings, environment secrets |

## Sources

- [Scribase docs: Tokens and safety](https://docs.scribase.com/docs/agents/safety)

[Create a scoped token](https://docs.scribase.com/docs/agents/safety)

## What is enforced even inside a write scope

- SQL on a connection that is a superuser drops to the project's postgres role for the transaction — an agent token is never a database superuser, even with sql:write.
- Drops, deletes, confirmed destructive SQL, restores and key rotations on production need project:<id>:admin specifically, or wait for a named approver.
- Agent tokens cannot mint other tokens, manage members, organization keys, billing or SSO, or claim temporary projects — no self-escalation, period.
- Default expiry is 8 hours; every request is rate-limited and logged with who made it and what decided each approval step.

## Sources

- [Scribase docs: Tokens and safety](https://docs.scribase.com/docs/agents/safety)
- [Scribase docs: Production approver](https://docs.scribase.com/docs/agents/prod-approver)

## FAQ

**Should a coding agent ever get write access to a database at all?**

Usually yes for it to do real work, scoped to what it needs: schema and data writes on branches and previews, SQL writes where the task needs them, migrations it can apply. The risk is not write access itself, it is write access with no expiry, no audit trail and no gate on destructive production actions — those three are what to add, not remove.

**What is the difference between sql:write and project:<id>:admin?**

sql:write lets a token run read-write SQL at all, but confirmed destructive statements (DROP, TRUNCATE, an unconditional DELETE or UPDATE) on production still need project:<id>:admin, or they wait for a named approver if one is set. sql:write alone is enough for all of that on a branch or preview.

**Can an agent token create another, more powerful token for itself?**

No. Agent tokens cannot mint tokens, manage organization members or keys, touch billing or SSO, or claim temporary projects — there is no path from a scoped agent token to a wider one without a human acting with their own credentials.

**Does a write-scoped token ever run SQL as a database superuser?**

No — even when the underlying connection is a superuser, an agent token's SQL drops to the project's postgres role for that transaction, so the scope on the token is the real ceiling, not the role of the connection underneath it.

## Related

- [Tokens and safety, full reference](https://docs.scribase.com/docs/agents/safety)
- [Approve an AI agent database change](https://scribase.com/approve-ai-agent-database-changes)
- [Never give an AI agent your API keys](https://scribase.com/never-give-ai-agent-api-keys)
- [Give an agent a database branch per task](https://scribase.com/database-branch-per-agent-task)