β€’πŸ‘€ By Richard Scorerβ€’
AIRustSecuritySSHMCP

Stop Giving AI Agents the Keys to Your Entire SSH Config

Why autonomous AI coding assistants with raw terminal access are a security liability, and how we engineered zero-trust connection pooling in Rust with 98.8% token savings.

If you’ve spent any time pair-programming with autonomous AI coding agentsβ€”whether it’s Claude Code, Cursor, Gemini, or custom agentic sidecarsβ€”you’ve likely handed them terminal execution permissions.

It feels intoxicatingly productive. You ask the agent to inspect a failing deployment, check container health across your cluster, or tail application logs, and it obliges in seconds.

Until you realize what you actually gave it.

In the background, your AI assistant isn’t just checking your staging box. It has complete, uninhibited read and execute access to your entire ~/.ssh/config. That includes your jump hosts, production database bastions, client servers, and private key identities.

One hallucinated shell expansion, one prompt injection hidden inside an untrusted Git repo, or one poorly scoped bash command, and your agent is executing arbitrary commands directly on production infrastructure.

Agentic SSH Terminal Demo


πŸ’₯ The Two Hidden Sins of Agentic SSH

When AI agents interact with remote servers via raw bash, two massive failure modes emerge:

1. The Blast Radius Problem (Zero Guardrails)

Standard AI terminal tools treat all SSH hosts equally. If it’s in your ~/.ssh/config, the model can reach it. There is no concept of β€œthis server is for development, but that server holds the customer database.”

Asking an agent to β€œclean up lingering Docker containers across our machines” can turn into an unrecoverable disaster in milliseconds.

2. The β€œToken Avalanche” & Reconnect Lag

Whenever an agent executes a command like ssh server 'journalctl -n 500' or docker ps -a, two things happen:

  • Connection Latency: Every single command undergoes a full SSH TCP handshake, key exchange, and authentication negotiation (typically 1.2s – 2.0s per invocation).
  • Context Poisoning: The command dumps 15,000 tokens of raw ASCII, ANSI color escape codes, and repeated column headers straight into the LLM context window.

Within 3 queries, your model hits its context limit, reasoning degrades, and your API bill explodes.


πŸ“Š Benchmark: Raw Bash vs. Agentic SSH

Here is what happens when an AI assistant queries container health and listening ports across 3 remote nodes:

Metric Raw Bash (ssh host 'docker ps && ss -tlpn') Agentic SSH (ash) Improvement
Context Consumption ~14,800 prompt tokens (raw ASCII/ANSI) 185 structured JSON tokens 98.8% Reduction πŸ“‰
Execution Latency 1,450ms (fresh TCP/SSH handshake) 0.4ms (pre-warmed pool) 3,600x Faster ⚑️
Host Guardrails ❌ Full access to all ~/.ssh/config hosts βœ… Cryptographic allow_hosts list Zero-Trust πŸ›‘οΈ
Session Cleanup ❌ Lingering background zombie processes βœ… Auto-teardown after 5m idle Clean 🧹

πŸ›‘οΈ The Architecture of agentic_ssh

To solve this, we built Agentic SSH (ash)β€”a dedicated, high-performance Model Context Protocol (MCP) server written in Rust.

Instead of letting agents execute unconstrained shell commands, agentic_ssh acts as a zero-trust cryptographic gateway between the AI and your servers.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       MCP Tool Call       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       Pre-Warmed SSH       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ AI Assistant    β”‚ ────────────────────────> β”‚ agentic_ssh (Rust MCP) β”‚ ─────────────────────────> β”‚ Remote Server   β”‚
β”‚ (Claude/Cursor) β”‚ <──────────────────────── β”‚                        β”‚ <───────────────────────── β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     Structured JSON       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        0ms Latency         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         (185 Tokens)            β€’ Strict Host Allowlist
                                                 β€’ Stream Parser & Truncation
                                                 β€’ Keepalive Connection Pool

⚑️ Key Architectural Pillars

1. Cryptographic allow_hosts Guardrails

By default, agentic_ssh operates on a strict Zero-Trust model. Even if your local SSH config lists 50 servers, the AI can only interact with hosts explicitly enumerated in .agentic_ssh.toml:

# Only staging and local nodes are accessible to the AI
allow_hosts = [
    "staging-app-01",
    "staging-db-01",
    "aruba-node"
]

# Production servers are invisible and strictly unreachable
deny_hosts = ["prod-*", "bastion-primary"]

If the agent attempts to target an unauthorized host, the tool call is rejected locally before a single network packet leaves your machine.


2. Pre-Warmed Rust Connection Pooling (0ms Handshakes)

Rather than spinning up and tearing down SSH processes on every command, agentic_ssh maintains an asynchronous in-memory connection pool built on russh and tokio.

  • Active Reuse: Consecutive tool calls to the same server execute in < 1ms with zero reconnect overhead.
  • Auto-Teardown: Idle sessions automatically close after 5 minutes of inactivity.

3. Squeezing 15,000 Tokens Down to 185 (98.8% Savings)

AI models don’t need 500 lines of kernel timestampsβ€”they need actionable status. agentic_ssh parses raw remote system outputs into compact, structured JSON telemetry:

{
  "host": "staging-app-01",
  "cpu_usage_pct": 14.2,
  "mem_used_gb": 3.8,
  "mem_total_gb": 16.0,
  "disk_free_pct": 72.4,
  "listening_ports": [80, 443, 8425],
  "failing_services": []
}

By compressing terminal noise into structured payloads, we slashed prompt token consumption by 98.8%, dramatically reducing model reasoning latency and operational costs.


4. Interactive Live-Stream TUI (ash watch)

When you want to oversee what your AI assistant is doing on your servers in real-time, agentic_ssh includes a high-performance terminal UI built with ratatui:

ash watch staging-app-01

You get a split-pane live stream of resource consumption, active SSH sessions, and tail logs across multiple hosts concurrently.


πŸ“¦ Getting Started in 30 Seconds

agentic_ssh is officially verified on the Anthropic Model Context Protocol Registry and available across macOS and Linux:

1. Install via Homebrew or Cargo

# macOS & Linux (Homebrew)
brew install sandbanks/tap/agentic_ssh

# Rust toolchain
cargo install agentic_ssh

2. Auto-Register with Your AI Tools

Run the self-install command to automatically configure Claude Desktop, Cursor, and other MCP clients:

agentic_ssh install

3. Configure Your Allowed Hosts

Create a simple ~/.config/agentic_ssh/config.toml or .agentic_ssh.toml in your project root:

allow_hosts = ["my-dev-box", "staging-cluster"]

🎯 Final Thoughts

Autonomous AI agents are only as safe as the boundaries we give them. Stop letting agents wander through your ~/.ssh/config unrestricted.

Give them dedicated, high-speed, zero-trust tools that keep your production infrastructure safe and your context windows clean.

RS

Richard Scorer

Independent software engineer building high-performance, sovereign tools and agentic primitives at sandbanks.tech.