7 October 2026·3 min read
AI Agents Can Run Commands Now. Here's How to Keep Them Safe.
AI agents can now run shell commands, edit files and browse the web. That's powerful, and risky. Simple guardrails every team should use.
AI assistants used to just answer questions. Now, many of them can act.
They can run commands in your terminal, edit your files, install packages, browse websites and call APIs. That makes them very useful. It also means a single bad command can delete files, leak secrets or break a system.
You don't need to be scared of AI agents. You need guardrails.
What Can Go Wrong
- A wrong command. The agent misunderstands and deletes the wrong folder.
- A bad instruction hidden in content. A webpage, a file or an email contains hidden text that tells the agent to do something harmful. This is called prompt injection.
- Leaked secrets. The agent reads a file with API keys and sends it somewhere.
- Too much access. The agent can reach production systems it never needed.
Most of these are not because the AI is "evil". They happen because the AI follows instructions, including ones it should not trust.
Guardrail 1: Give the Least Access Needed
Don't give an agent your admin account or production keys. Give it only what it needs for the task. If it only needs to read code, don't let it push to production. If it only needs one folder, don't give it the whole disk.
Guardrail 2: Ask Before Risky Actions
Some actions should always need a human "yes":
- Deleting files or data
- Changing production systems
- Spending money
- Sending messages or emails to real people
- Installing new packages
Simple commands, like listing files, can run freely. Risky ones should stop and ask.
I built a small open-source library called shellsafe for exactly this. It checks a shell command before an agent runs it and decides whether to allow it, ask first or block it.
Guardrail 3: Run in a Safe Space
Let agents work in a sandbox: a container, a separate folder or a test environment. If something goes wrong, the damage stays inside.
Guardrail 4: Treat Outside Content as Untrusted
Anything the agent reads from outside (web pages, documents, emails, search results) might contain hidden instructions. My rule is simple: outside content is data, not instructions. An agent should never follow orders just because they appear in a page it read.
The same goes for what agents produce. AI-written Markdown can hide links or images that leak data when shown, which is why I wrote safemd to make AI-generated Markdown safe to display.
Guardrail 5: Keep Secrets Away
- Don't keep real API keys in files the agent can read.
- Use separate, limited keys for agent work.
- Mask secrets in logs and prompts.
Guardrail 6: Log Everything
Keep a record of what the agent did: which commands, which files, which websites. If something goes wrong, you can see exactly what happened and fix it quickly.
A Simple Starting Policy
- Agents start with read-only access.
- Risky actions always need human approval.
- Agents run in a sandbox, never directly on production.
- No real secrets inside the agent's reach.
- Everything is logged.
Conclusion
Treat an AI agent like a talented new team member on their first day. Give them useful work, clear limits and close supervision. Trust grows with time and evidence, for agents just like for people.
Newsletter
Get New Posts by Email.
New posts on building, shipping and leading tech teams, sent to your inbox. No spam, and you can unsubscribe any time.
Keep Reading
More Posts.
26 October 2026·2 min
Never Paste Customer Data Into AI. Do This Instead.
Pasting customer data into AI tools is fast, and risky. How to get the benefits of AI without leaking personal data, with simple steps any team can follow.
Read Post29 October 2026·2 min
Every Webhook You Receive Could Be Fake
Webhooks tell your app that a payment succeeded or an order changed. If you don't verify them, anyone can send a fake one. How to handle webhooks safely.
Read Post21 October 2026·3 min
What Is MCP, and Why Should Your Business Care?
MCP, the Model Context Protocol, is becoming the standard way to connect AI assistants to your tools and data. A plain-English guide for leaders.
Read Post