blog /

Coding Agent Remote Server Security: Access and Secrets

A remote box that runs coding agents tends to hold keys and tokens for several projects at once, and the agent can reach whatever its account can reach. Good coding agent remote server security comes down to five steps:

  1. Give the agent its own account on the server, with its own SSH key. Never your personal key, never a forwarded agent.
  2. Reach the box through a bastion, and make the bastion key unable to do anything except jump.
  3. Hand out git access as one read-only deploy key per repository.
  4. Keep secrets out of the agent's files and environment, then enforce that with rules the agent cannot edit.
  5. Test every limit as the agent would hit it, and keep a log you can read afterwards.

The trust boundary on a remote box

On a shared server the boundary is the Unix account, not the folder the agent started in. In Claude Code's Manual mode the working directory boundary is a permission prompt, "so a Bash command you approve can still write anywhere your user account can". Its sandbox, when on, lets shell commands read most of the machine by default, "including credential files such as ~/.ssh and ~/.aws/credentials", and those commands inherit the environment, secrets included.

The sandbox covers shell commands only. File tools, MCP servers and hooks run outside it, so a denyRead entry does not stop the Read tool. That needs a permission rule, so you want both.

The threat model is short. A repository, a web page or a tool result can carry instructions the agent obeys (prompt injection, in Claude Code's words). So ask of every credential: can the agent's account reach it? If yes, assume the agent can be talked into using or sending it.

Threats and common unsafe shortcuts

ShortcutWhy it hurtsDo this instead
ForwardAgent yes or ssh -A into the boxPer the OpenSSH docs, users who can bypass file permissions on the remote host can use your local agent's keys through the forwarded connectionA jump host (ProxyJump), which the ssh manual calls a safer alternative
Your personal key on the serverThe agent inherits everything that key opensOne key per box, used by one account
Password logins left onPasswordAuthentication defaults to yes in sshdSet it to no, keys only
One account for every projectEvery project's files and keys sit inside one boundaryOne account per trust level
Turning permission checks off to stop the promptsThe prompts are the boundaryKeep the sandbox on, and lock bypass mode in managed settings

In Claude Code, permissions.disableBypassPermissionsMode set to "disable" locks bypass mode; the docs say it is most useful in managed settings, where users cannot override it.

Coding agent remote server security: the bounded setup

Steps 1 and 2: key scope and the bastion

On your laptop, give the bastion and the box separate keys. This is a plain ~/.ssh/config:

Host bastion
    HostName bastion.example.com
    User jump
    IdentityFile ~/.ssh/agent_bastion_ed25519
    IdentitiesOnly yes
    ForwardAgent no
    StrictHostKeyChecking yes

Host devbox
    HostName devbox.internal
    User agent
    ProxyJump bastion
    IdentityFile ~/.ssh/agent_devbox_ed25519
    IdentitiesOnly yes
    ForwardAgent no
    StrictHostKeyChecking yes

IdentitiesOnly stops ssh from offering every agent key to every host. StrictHostKeyChecking yes refuses a host key not already in known_hosts, so put the real one there first.

On the bastion, the key's line in authorized_keys is where you cut its power:

restrict,port-forwarding,permitopen="devbox.internal:22",command="echo jump only; exit 1" ssh-ed25519 AAAA... agent-bastion

Per sshd(8), restrict switches off port, agent and X11 forwarding, PTY allocation and ~/.ssh/rc. port-forwarding re-enables forwarding, permitopen limits it to one destination, and command= replaces any shell.

The box gets a different key, listed only in its own authorized_keys, so neither key does the other's job. OpenSSH can also sign short-lived user certificates (ssh-keygen -s ... -V +1h), which the server trusts through TrustedUserCAKeys.

Step 3: git access

A GitHub deploy key is "an SSH key that grants access to a single repository", read-only unless you grant write. Per GitHub, such keys usually have no passphrase and do not expire, so rotate them yourself. One repository means one key.

Keep it outside ~/.ssh, because step 4 hides that directory from sandboxed commands, and point each repository at it. core.sshCommand replaces ssh for git fetch and git push, and the GIT_SSH_COMMAND variable overrides it:

git config core.sshCommand "ssh -F /dev/null -i $HOME/.deploy/deploy_app -o IdentitiesOnly=yes -o UserKnownHostsFile=$HOME/.deploy/known_hosts"

Put the pinned github.com host key in ~/.deploy/known_hosts. The agent can read this one key, which is why it is read-only and limited to one repository.

Step 4: files and secrets

On the box, as the agent account, an example ~/.claude/settings.json for Claude Code combines permission rules with the sandbox:

{
  "permissions": {
    "deny": [
      "Read(~/.ssh/**)",
      "Read(~/.aws/**)",
      "Read(./.env)",
      "Read(./.env.*)",
      "Bash(ssh *)",
      "Bash(scp *)",
      "Bash(curl *)"
    ]
  },
  "sandbox": {
    "enabled": true,
    "failIfUnavailable": true,
    "allowUnsandboxedCommands": false,
    "credentials": {
      "files": [
        { "path": "~/.ssh", "mode": "deny" },
        { "path": "~/.aws/credentials", "mode": "deny" }
      ],
      "envVars": [
        { "name": "GITHUB_TOKEN", "mode": "deny" }
      ]
    },
    "network": {
      "allowedDomains": ["github.com"]
    }
  }
}

Deny rules are checked first, and an allow rule cannot carve an exception out of one. failIfUnavailable makes Claude Code exit at startup when the sandbox cannot start; by default it runs commands unsandboxed. allowUnsandboxedCommands: false removes the unsandboxed retry. credentials blocks reads of the listed files inside the sandbox and unsets the listed variables before each sandboxed command. There is no built-in credential list, so only what you name is protected.

Know the limits. Git over SSH inside the sandbox works on Linux once github.com is allowed, but Claude Code's docs say it fails on macOS even then: use an HTTPS remote, or add git fetch *, git pull * and git push * to sandbox.excludedCommands, which lets those commands reach any host. A Bash deny rule matches the command as written, and the docs call argument patterns fragile, so Bash(curl *) is a speed bump (and Bash(ssh *) does not stop git's own ssh call); the sandbox's domain allowlist is the real network control. Read deny rules cover the Read tool and, best effort, Grep and Glob. The only control that never depends on a pattern matching is a key the account does not have.

Step 5: process persistence and transport

tmux sessions survive an SSH timeout or a detach. That is the feature and the risk: a detached agent keeps acting with its account's access while you are away. Run tmux as the agent account only. Its default socket sits in a tmux-UID directory under /tmp, closed to every user except the owner and root, and -L name gives each agent its own server. When the work ends, end the session (kill-session).

For transport, ssh provides "secure encrypted communications between two untrusted hosts over an insecure network", and ProxyJump forwards TCP through the jump host. Knowing the host is the right one is why the host keys are pinned above.

Test exceptions, denial and escalation

Before the first real task, run these from your laptop and the agent account, and expect the results on the right:

Try thisExpect
ssh bastion id with the bastion keyThe command= message, exit 1, no shell
A forward through the bastion to a port you did not permitNo data comes back
The bastion key against the box, and the box key against the bastionA Permission denied error
Connect with an empty known_hostsHost key verification failed
Ask the agent to read ~/.ssh/id_ed25519Denied by the rule, not by the model's good manners
Run git fetch as the agent, once with the deploy key and once with any other keyWorks with the deploy key, fails with the other
Start Claude Code with the sandbox dependencies missingIt exits (that is failIfUnavailable)

A small script covers the account itself. Run it as the agent user:

#!/usr/bin/env bash
# Exit 1 on any finding, exit 2 if it cannot check.
set -u
command -v grep >/dev/null || { echo "FAIL: grep is missing" >&2; exit 2; }
bad=0
fail() { echo "FAIL: $*" >&2; bad=1; }

[ -z "${SSH_AUTH_SOCK:-}" ] || fail "an ssh-agent socket is reachable (SSH_AUTH_SOCK is set)"

vars=$(compgen -e | grep -E -i 'TOKEN|SECRET|PASSWORD|API_?KEY' || true)
[ -z "$vars" ] || fail "secret-looking variables in the environment: $(echo $vars)"

for f in "$HOME/.aws" "$HOME/.netrc"; do
  [ ! -e "$f" ] || fail "$f exists"
done

keys=$(grep -l -s 'PRIVATE KEY' "$HOME"/.ssh/* || true)
[ -z "$keys" ] || fail "private keys in ~/.ssh: $(echo $keys)"

[ "$bad" -eq 0 ] && echo "preflight ok"
exit "$bad"

It checks only these four things, so a clean run does not mean the box is safe. If grep is missing it refuses to pass.

Escalation is the other half. Decide which actions always go to a human (deleting, releasing, production, money, anything that leaves the box), then try one on purpose. The practical safety model for agent permissions goes deeper on drawing those lines, and the risks of skipping permissions covers what happens when they are not drawn.

How to audit the resulting action

Two records answer "what did the agent do on that box":

  • The server's log. sshd records the start, authentication and end of each connection; LogLevel defaults to INFO and VERBOSE is the next level up. Check what your sshd writes at that level before relying on it. With one account and key per agent, entries can be tied to one agent.
  • The agent's transcript. Claude Code writes JSONL to ~/.claude/projects/<project>/<session-id>.jsonl, one object per message, tool use or metadata entry, kept 30 days by default (cleanupPeriodDays). The format changes between versions, so use /export for anything you parse.

For the full method, see how to audit autonomous coding-agent actions.

Remote agent security checklist

  • Agent has its own account on the box, no shared account across projects
  • Own key per box; no personal key, no ForwardAgent, IdentitiesOnly yes
  • Bastion key restricted: restrict, one permitopen, command=
  • PasswordAuthentication no on bastion and box
  • Host keys pinned, StrictHostKeyChecking yes
  • One read-only deploy key per repository, kept outside ~/.ssh, rotated by you
  • Deny rules for credential paths, and the sandbox with failIfUnavailable
  • Bypass mode disabled in managed settings
  • tmux runs as the agent account, sessions ended when work ends
  • Preflight script clean, every row of the test table tried once
  • A named list of actions that always go to a human

Running this with qoop

qoop reaches a server through the system ssh and your own ~/.ssh/config, so the devbox block above is what it connects through: qoop remote add devbox agent@devbox lists that server's spaces beside your local ones. The key scope is unchanged. qoop does not replace any setting in this post, and it is not a sandbox.

It helps with persistence. Everything in a remote space runs on the server, so agents keep working while your laptop sleeps. If the connection drops, the spaces show as offline within about fifteen seconds and return by themselves. Closing a terminal also ends jobs that escaped the shell's process group, which helps when you end a session and want nothing left running.

For the human gate, qass is the supervisor that answers other agents inside its rules. Deleting, releasing, production, money and anything external always go to you, and it never chooses "always allow" on a permission menu. It agrees by itself only to a command that is read-only, or reversible and inside the repo. Corrections are saved as lessons; a lesson may let it settle one kind of reversible step but never overrides anything that always asks, so these boundaries are fixed, not learned. This explains the design; it is not a security certification, and the layers above still do the enforcing.

Start with one box

Apply the checklist to one server and run the test table first. To supervise agents on remote machines from one terminal, sign up at qoop.si.