Skip to content
Browse the documentation

SSH Sessions

Run SSH commands for AI agents through AgentLock with command rules, host-key pinning and approval.

How do SSH commands work?

AgentLock lets your agents run commands on remote hosts (homelab, internal servers, VPS) without ever seeing SSH private keys. There are two modes:

One-shot ssh.run (all plans): the SDK's client.sshRun({credentialId, host, user, command}) connects, runs, disconnects in one action; host, user and port must match the credential. The credential is decrypted in memory only for the duration of the call. Free, Pro, and Team can all use this.

Persistent sessions (ssh.open → ssh.run → ssh.close, Pro/Team): the SDK's client.ssh.open({credentialId}) opens a long-lived SSH connection on AgentLock's servers and returns a session handle. Subsequent session.run(command) calls reuse the connection (saves the connect-and-auth cost on every command). Use client.ssh.list() to discover your active sessions across processes, and client.ssh.adopt(id) to re-bind to a known session. Always close with session.close() (idempotent — safe in finally).

The flow for both:

  1. Agent requests ssh.run (one-shot) or ssh.open (persistent) with a credential reference and command/target.
  2. AgentLock takes host, user and port from the credential and checks your SSH policy: allowed hosts, allowed users, and command rules.
  3. ssh.open always requires approval. ssh.run is policy-evaluated per command (ALLOW / REQUIRE_APPROVAL / BLOCK). SSH actions are admin-class, so an ALLOW still needs approval unless admin auto-approval is switched on in the policy's Danger Zone.
  4. After approval, AgentLock decrypts the stored SSH credential, optionally starts a WireGuard tunnel, opens (or reuses) the SSH connection, runs the command and captures stdout/stderr (up to 64 KB each).
  5. Output is redacted for secrets before storage and delivery.

How do I configure SSH command rules?

In Policies, expand the SSH block and add:

  • Allowed hosts — exact names or wildcards (*.homelab.internal).

  • Allowed users — SSH usernames (e.g. deploy, readonly).

  • Command rules — glob patterns with a decision. Write plain commands and use * (any run of characters) or ? (one character) for wildcards:

    • systemctl status * → ALLOW (safe read-only)
    • git pull and git status → ALLOW
    • systemctl restart * and docker restart * → REQUIRE_APPROVAL
    • rm *, dd *, mkfs * → BLOCK (destructive)

    Need the full regex power? Wrap the pattern in /…/ — e.g. /^(rm|dd|mkfs)\b/. Older regex rules that start with ^ or $ keep working as-is.

  • Default decision — what to do when no pattern matches (recommended: REQUIRE_APPROVAL).

Safety guardrail: even if a command matches an ALLOW rule, AgentLock escalates it to REQUIRE_APPROVAL unless you have explicitly opted in to admin auto-approval in the policy's Danger Zone. This prevents a typo in a pattern from quietly enabling unsupervised shell access. A command with shell control characters (;, |, &, $, backticks, redirects, line breaks) matched by a glob pattern always needs approval, even with admin auto-approval on.

Is SSH available on my plan?

One-shot ssh.run is available on all plans (Free / Pro / Team) and counts toward the monthly action quota — there's no per-session concurrency limit on it.

Persistent SSH sessions (ssh.open) are gated by plan:

  • Free — 0 (use client.sshRun for one-shot calls)
  • Pro — 2 concurrent
  • Team — 5 concurrent

A session lasts up to 20 minutes on Pro and up to 60 minutes on Team. The limit is enforced at the Gateway when ssh.open is requested. If you're at the limit, a 429 is returned with an explanation; close an existing session or upgrade.

The practical requirements (in addition to plan):

  • an SSH credential in Credentials
  • a matching SSH policy in Policies
  • network reachability from AgentLock's servers to the target host (or a WireGuard credential — see VPN section)

What does AgentLock store about SSH actions?

For each SSH action we store:

  • Approval requests & timeline entries with encrypted preview payloads (host, user, command).
  • Command output — trimmed to 64 KB and passed through our redaction layer (passwords, tokens, private-key blocks are scrubbed before storage).
  • Operational metadata such as workspace, agent, approval id, host, port, username, exit code, and whether a VPN tunnel was used.

We do not store your SSH private keys in plaintext — credentials are envelope-encrypted with a Master Key (same model as other credentials).

How do I pin an SSH host-key fingerprint?

Pinning the server's host-key fingerprint protects against man-in-the-middle attacks where an attacker redirects your SSH traffic to a look-alike host. Two optional fields on the SSH credential control this:

  • host_key_fingerprint — SHA-256 fingerprint of the server's host key. AgentLock accepts both hex (ssh-keyscan -t ed25519 host | ssh-keygen -lf - -E sha256) and the OpenSSH base64 form (SHA256:…) — paste whichever one your tooling emits.
  • require_host_key_fingerprint — When true, AgentLock refuses to connect at all unless a fingerprint is pinned. Use this for production hosts where TOFU ("trust on first use") is not acceptable.

If no fingerprint is pinned and require_host_key_fingerprint is false, the first connection accepts the server's key and logs its observed fingerprint — equivalent to OpenSSH StrictHostKeyChecking=accept-new. Capture the logged fingerprint and add it to the credential so subsequent connections verify it.

How to capture the fingerprint ahead of time:

text
ssh-keyscan -t ed25519,rsa your.host.example 2>/dev/null | ssh-keygen -lf -

You can also run any ssh.run command once in TOFU mode and copy the fingerprint AgentLock logs — then pin it and flip require_host_key_fingerprint to true for subsequent commands.

Can I reach hosts that are only reachable through a VPN?

Yes. Link an SSH credential to a WireGuard credential via the VPN dropdown on the SSH credential form. When an ssh.run fires, AgentLock spins up an isolated per-request WireGuard tunnel, routes the SSH TCP connection through it, runs the command, and tears the tunnel down again immediately.

Key properties:

  • The tunnel is per-request, not workspace-wide. Two concurrent SSH commands on the same VPN credential run in two independent tunnels with separate source IPs.
  • SSRF checks still apply to hosts outside the tunnel's AllowedIPs — cloud metadata endpoints and private ranges that aren't announced by the peer stay blocked.
  • The VPN credential's private and preshared keys are never logged or written to persistent storage.

See the VPN (WireGuard) section for how to create a VPN credential and for the plan limits (VPN credentials: Free 0, Pro 3, Team 10).

SSH Sessions | AgentLock Docs