How to Configure Codex SQL Server Credentials
To set up codex sql server credentials, create a scoped user with read roles. Then pass those details to the local tool that runs queries for your agent. Teams often start by sharing a personal login or an admin key for speed. When an AI coding agent uses broad roles, a bad query can drop tables. It can also pull sensitive rows from every table in the database. How to set up codex sql server credentials SQL Server separates server logins from database users. A database user is the identity of
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
To set up codex sql server credentials, create a scoped user with read roles. Then pass those details to the local tool that runs queries for your agent. Teams often start by sharing a personal login or an admin key for speed. When an AI coding agent uses broad roles, a bad query can drop tables. It can also pull sensitive rows from every table in the database.
How to set up codex sql server credentials
SQL Server separates server logins from database users. A database user is the identity of a login inside one specific database. When someone needs to reach many databases on an instance, admins create a login. That login resides in the master database and maps to users in target databases.
For an AI agent, you usually want a tighter scope. SQL Server offers contained database users for this exact need. A contained user has a password and lives inside one database. It does not tie back to a login in the master database. Before creating one, an admin must turn on contained databases on the server. The admin must also turn on the setting on the target database itself.
Once the user exists, you assign a role to control what it can do. Every user sits in the public role, which includes basic permission to connect. For read tasks, admins often add the user to the fixed data reader role. Members of this role can read all data from all user tables and views. If you want to block write actions, you can add the deny data writer role. Members of that role cannot add, change, or delete any table data.
Never put an agent user into the fixed database owner role. That owner role can run all maintenance tasks and can even drop the database. Note that you cannot change the permissions built into SQL Server fixed roles.
What native roles solve and what they leave open
Scoped database users and fixed read roles solve the first layer of risk. They decide which database the agent can enter and block table writes at login. If the agent tries to delete rows, SQL Server stops the statement right away.
Still, native roles leave a big operational gap during live sessions. The fixed data reader role lets the user read every user table and view. You cannot change that fixed role to hide specific columns with private data. When the agent runs a query, the database returns emails and phone numbers in full. Card numbers and national IDs also come back in plain text if they exist.
Ephemeral Credentials + Kubernetes API Server Access: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Storing passwords on developer machines creates another problem for security teams. AI coding agents run local scripts or tools that read local database strings. Anyone or any process with file access on that machine can read the password. Rotating those shared passwords across a whole engineering team takes time and breaks local setups. Also, database logs only show that the shared agent user ran a query. They do not show which developer or prompt triggered that action in flight.
How to reduce risk in daily agent workflows
Start by creating a separate contained user for agent tasks instead of reusing human logins. Pair the fixed read role with the deny write role for safety. If the agent only needs a few tables, skip the fixed read role. Grant select permissions only on the specific views or tables the task requires.
Keep local secrets out of source control and project text files. Review what queries the agent plans to run before approving shell commands. Even with careful setup, static credentials on laptops remain hard to track and rotate.
Check SQL Server batches and results on the wire
SQL Server logins and roles decide who connects. They do not check what each TDS batch does or mask sensitive values in returned rows. With hoop.dev, you run an open-source proxy, a sidecar for your SQL Server, inline in the TDS wire protocol. On every batch an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.
Before a batch hits the server, hoop.dev guardrails refuse disallowed actions with a native TDS error or hold risky statements for approval. On the way back, hoop.dev data masking rewrites sensitive values in supported result columns in memory, and every decision is logged. Explore the MIT-licensed project on GitHub.
Frequently asked questions
Should I use a master login or a contained user for an AI agent?
Use a contained database user when the agent only needs one or a few databases. This keeps the user inside the target database without needing a login in master.
Does the fixed data reader role hide sensitive columns from Codex?
No, the fixed data reader role grants read access to all user tables and views. Because fixed role permissions cannot be changed, it returns all columns including emails or card numbers by default.
How can I make sure an agent user never changes table data?
Add the database user to both the fixed data reader role and the deny data writer role. The deny role blocks any attempt to add, change, or delete rows in user tables.
Related guides
In this post