← Back to library

Give an agent read-only access to servers and databases

An engineer asked Hacker News how to let Claude Code run DevOps checks over SSH and query databases without approving every command. The replies converged: give the agent its own read-only accounts, keep personal data out of reach, route writes through reviewed scripts, and enforce limits outside the agent rather than trusting an allowlist.

  • OutcomeLet a coding agent investigate logs and data without the power to change or delete anything.
  • SetupUnder an hour
  • LevelIntermediate
  • Creditnico on Hacker News
View original
Works with
Claude CodeCustom agent

Published Oct 20, 2026Updated Oct 20, 2026AI dry run on sample input: passed Oct 20, 2026Source verified Oct 23, 2026

When should you use it?

  • An agent helps with log searches, file inspection or database lookups
  • You are tired of approving every repetitive read command
  • MSPs letting agents troubleshoot client systems

Not for: Giving an agent production write access; Databases holding personal data without table-level restrictions or redaction

What do you need, and what do you get?

You need

  • The systems the agent needs to read
  • Your database engine and SSH setup
  • Which tables or paths hold sensitive data

You get

  • A least-privilege access plan
  • Setup steps for read-only DB and SSH accounts
  • A change process for anything that writes

How does it work, step by step?

  1. Create agent-only accountsA separate DB role and SSH user for the agent, never your own credentials.
  2. Make them read-onlyGrant SELECT on named tables only; restrict the SSH user's shell and file permissions.
  3. Enforce outside the agentUse database permissions, a restricted shell or a proxy, not instructions in a prompt.
  4. Route writes through reviewThe agent writes a script against a dev copy; a person reviews it in version control and runs it.

The prompt

Our own prompt, inspired by nico on Hacker News and written to work in Claude Code and Custom agent. Values in lime are placeholders.

Fill in the blanks (optional; the copied prompt uses your values)

Prompt4 variables
Act as a security-minded systems engineer. I want an AI agent to help me investigate systems, but it must not be able to change anything.
Environment: {systems} (database engine: {db_engine}; SSH hosts: {hosts}).
Sensitive data lives in: {sensitive_locations}.
Produce:
1) A least-privilege plan: a dedicated database role and a dedicated SSH account for the agent, with exactly what each may read.
2) The setup steps or SQL grants for {db_engine}, excluding the sensitive locations.
3) How to enforce the limits outside the agent (permissions, restricted shell, replica, proxy). Do not rely on telling the agent what not to do.
4) A change process: the agent drafts a script against a non-production copy, a person reviews it in version control and runs it.
5) Remaining risks, such as heavy queries, with a mitigation for each.

Inspired by nico on Hacker News: Ask HN: How do you safely give LLMs SSH/DB access?. The prompt above is written by playbooks.bot in our own words; nothing from the original is quoted.

What can go wrong?

  • Command allowlists are easy to bypass: many CLI tools accept flags that write files or run other commands.
  • Even read-only queries can slow a production database; use a replica and query timeouts.

Our take

This thread is useful because the replies are close to unanimous and come from people who run production systems. The question was about convenience; the answer was about blast radius. The pattern we would put in front of any MSP or IT team is simple: an agent gets its own identity with the smallest permissions that let it do the job, and the controls live in the database, the operating system or a proxy, not in a prompt. Writes become reviewed scripts that a person runs. That is slower, and several commenters said the trade is worth it. Our prompt turns the thread's advice into a plan you can apply to your own environment, and it refuses to recommend anything that relies on the agent behaving well. We tested it on a sample setup with a Postgres database holding a customer table and two Linux hosts; it produced read-only roles, kept the customer table out of scope, and pushed all changes into a review step.

Where the time goes back: Once the agent can only read, routine investigation runs without a click-to-approve on every command, and reviews focus on the few changes that matter.

FAQ

Is a list of approved commands enough?
Commenters with security experience said no. Agents can find substitute tools, and ordinary commands accept dangerous flags. Put the limits in the account permissions or a proxy, where the agent cannot talk its way around them.
What about personal data?
Keep it out of the agent's reach entirely, or restrict the role to tables without it. One commenter suggested redacting extracts with an open-source PII tool before an agent sees them.

Source and credit

Inspired by nico on Hacker News. We describe the idea in our own words, link to the original, and wrote the prompt ourselves; nothing is quoted.

Inspired by
Ask HN: How do you safely give LLMs SSH/DB access?
Creator
nico on Hacker News
Published on
Hacker News
Original date
Jan 14, 2026
License
Not openly licensed (the poster keeps all rights), so we quote nothing and link to the original
Originally for
Claude Code
AI dry run
Oct 20, 2026: passed. Dry-run tested by our AI test agent on sample input. No reliance on allowlists in the prompt; sensitive tables excluded; write path goes through review.
AI dry run on sample data; not run with live connected accounts. The playbooks.bot test agent filled the prompt with synthetic inputs, produced the output and checked it against the page's stated outputs and guardrails.
Verified
Oct 23, 2026: source link resolves to the original, the credited creator published it, our excerpt or prompt matches it, and the license allows our use.

Are you the creator? Claim or correct this page.

More in IT & Security

All 82 IT & Security playbooks →

Related playbooks

IT & SecurityWorkflow✓ AI dry run

Distill agent sessions into shared memory every night

Save each completed agent session to its own transcript file, have one analyzer agent per transcript verify, enrich and organize small linked memory files, run an organizer once to merge duplicates and keep an index current, then attach the store to the agent's next session with read access only and repeat the pass nightly on new sessions.

Credit: Anthropic

An afternoon+
IT & SecuritySkill✓ AI dry run

Find repeat fixes and good habits in your team's PRs

Have Claude Code look across a chosen window of commits and pull request review comments for the same fix or review note coming up again and again, suggest turning the top ones into a project rule or skill you write in your own words, and list good practices already in the repo that other teams could copy.

Credit: anthropics

Under an hour
IT & SecuritySkill✓ AI dry run

Score your team's AI coding adoption with repo evidence

Have Claude Code rate a software team on seven areas of AI coding adoption, from tool access to guardrails, using evidence from the repo where you allow it and your answers elsewhere, then write a self-contained HTML report with the overall step, the weakest area and next moves.

Credit: anthropics

Under an hour
IT & SecurityWorkflow✓ AI dry run

Run n8n agents on a client's own model server

When a client will not let documents leave their building, point your n8n agent at the language model they host themselves through the standard OpenAI chat node, match the endpoint type their server supports, get the real context size from them, compare answers against the hosted setup, and add an alert for when their server goes down.

Credit: kartike

Under an hour
IT & SecurityWorkflow✓ AI dry run

Triage assigned tickets into draft PRs or questions

Classify each assigned ticket as ready or not; ready ones get a draft pull request, the rest get a drafted clarifying question.

Credit: u/MountainByte_Ch on r/ClaudeAI

An afternoon+