Let a coding agent open SSH to your server for a limited time

By

Give Claude Code or Codex SSH to a DigitalOcean Droplet one command at a time with Firewall Manager run, a time cap, and rules for what it may not touch.

You want your coding agent to check the disk on a server, read a log, or restart a service. It needs SSH for that. You don’t want port 22 open all afternoon, and you don’t want the agent editing your cloud firewall however it likes.

Firewall Manager is a Mac app with a companion CLI for DigitalOcean. Its run command opens TCP 22 for your Mac’s current public IPv4, runs one local command, and closes that rule when the command exits or its time runs out. That shape fits an agent well. Each SSH call carries its own open and close, and the agent never holds access between calls.

This page is about the handoff: what the agent can discover by itself, what you write in its instructions, the time cap, and the commands it must leave to you. The manual versions are in Open SSH on DigitalOcean for a few minutes and Run one SSH command and close the firewall rule.

What you need

Firewall Manager needs macOS 14 or later, on Apple silicon or Intel. After purchasing it, download the ZIP from your Polar receipt, unzip it, and move the app to Applications. Keep it there: the cleanup job needs to find the bundled executable later.

On the DigitalOcean side, create a custom API token with account:read, droplet:read, firewall:read and firewall:update. Paste it into the app and click Connect DigitalOcean, or use Use doctl login. The token goes into the macOS Keychain, and the agent never sees it.

The server needs a dedicated Cloud Firewall attached directly to one Droplet, with no tag attachments, and that Droplet can’t have a second firewall. The app checks this before it opens anything.

Open Settings and choose Install Companion CLI. That links firewall-manager into ~/.local/bin. The agent runs commands in its own shell, so that folder has to be on the PATH it sees too. This is for an agent that runs on the same Mac, like Claude Code, Codex or Cursor in your terminal. A cloud agent on someone else’s machine has no access to your Keychain or your IP.

The preflight is one command, run from the agent’s shell:

firewall-manager --version
firewall-manager 1.1.1

If the agent gets command not found here, fix the PATH before anything else.

Let the agent read what the CLI can do

An agent that doesn’t know a tool guesses its flags. It tries --help variants, invents an option, and burns a few turns on errors. Worse, it may decide the tool can’t do the job and fall back to something you didn’t want, like asking you to open port 22 to everyone. Firewall Manager ships a manifest for this. capabilities --json prints the supported tasks with the exact command for each, plus the release history. It reads nothing from DigitalOcean, so it’s safe to run any time.

firewall-manager capabilities --json
{
  "capabilities" : [
    {
      "command" : "firewall-manager list",
      "description" : "List DigitalOcean firewalls and SSH rules"
    },
    {
      "command" : "firewall-manager status",
      "description" : "Check tracked temporary access"
    },
    {
      "command" : "firewall-manager open FIREWALL_ID --minutes 15",
      "description" : "Open SSH for the current IP for 15 minutes"
    },
    {
      "command" : "firewall-manager close FIREWALL_ID",
      "description" : "Close tracked access"
    },
    {
      "command" : "firewall-manager run FIREWALL_ID -- ssh user@server uptime",
      "description" : "Run a local SSH or SCP command and close access afterward"
    },
    {
      "command" : "firewall-manager auth --from-doctl default",
      "description" : "Import an existing doctl login into Keychain"
    }
  ],
  "changelog" : [
    {
      "changes" : [
        "install-cli prints paths without escaped slashes.",
        "auth --stdin checks the keychain first and explains how to unlock it when run over SSH."
      ],
      "date" : "2026-11-05",
      "version" : "1.1.1"
    },
    {
      "changes" : [
        "The app installs updates itself once you enter the license key from your Polar receipt in Firewall Manager → License…."
      ],
      "date" : "2026-11-04",
      "version" : "1.1.0"
    },
    {
      "changes" : [
        "Native Mac app, shared Keychain credentials, temporary IP rules and background cleanup."
      ],
      "date" : "2026-10-27",
      "version" : "1.0.0"
    }
  ],
  "name" : "firewall-manager",
  "summary" : "Manage temporary DigitalOcean SSH access from the Mac app or terminal.",
  "version" : "1.1.1"
}

Notice what’s missing. The --help text also lists block FIREWALL_ID --confirm, auth --stdin, install-cli and watch. The manifest leaves block out. That’s the one command that removes SSH rules Firewall Manager didn’t create, and it’s the one I’d keep away from an agent anyway.

Write the rules into AGENTS.md

The manifest says what the CLI can do. It doesn’t say what you allow. That part goes in the file your agent reads at the start of every chat: AGENTS.md for Codex and Cursor, CLAUDE.md for Claude Code. Without it, a helpful agent will pick whatever works. It might use open and leave the rule up for an hour, or retry a refusal with block --confirm because the error told it SSH was already allowed. As I wrote in how to prevent AI agents from taking irreversible actions, a prompt is advice, not a lock. Firewall Manager’s own checks are the hard boundary, and these rules keep the agent from leaning on them.

This is an example to adapt. The firewall ID, user and address are made up:

## Server access

- The production Droplet is admin@203.0.113.25.
- Its firewall ID is 3b0f2c1e-8a4d-4e7b-9c51-6f2a1d9e0b37.
- Reach it only through `firewall-manager run <id> --minutes N -- ssh ...`.
  One remote command per call. Keep N as small as the job allows.
- Run `firewall-manager status` first. Continue only if that firewall's
  `ssh` is `closed`.
- Never run `firewall-manager open`, `block`, `auth` or `install-cli`.
- Never close access you didn't open. If `run` refuses, stop and show me
  the exact error.
- Read-only commands don't need my approval. Ask before anything that
  restarts, deletes or changes files on the server.

What is AGENTS.md covers where the file goes and how agents pick it up. The last rule is about the server, not the firewall. Firewall Manager limits when port 22 is reachable. It doesn’t limit what the agent does once it’s in.

Hand the agent one firewall ID

run takes a DigitalOcean firewall UUID. A name like “shop-db-01” isn’t accepted. If the agent passes something that isn’t a UUID, the request stops with Use a firewall ID returned by list. You could let the agent call list and pick a firewall by name. I’d rather not. Your account may have a staging firewall with a similar name, and the agent can’t tell which one you meant. Copy the UUID yourself and put it in the instructions file, so there’s exactly one server the agent can open.

firewall-manager list
firewall-manager status

list prints every firewall as JSON, with the UUID in id, plus droplet_ids, tags and inbound_rules. status prints one object per firewall with its id, name, an ssh field, a settled flag and the tracked lease, if there is one. The ssh field is the one the agent checks:

  • closed: no inbound rule allows SSH. run can open it.
  • temporary: Firewall Manager is tracking access it opened, from the app, the CLI or another agent.
  • unmanaged: some other rule already allows SSH.

settled is false while DigitalOcean is still applying a change. An agent that sees it should wait and check again, not fire a second request.

Let the agent run one command at a time

This is the core of the setup. The agent puts firewall-manager run <id> -- in front of the SSH command it wanted to run anyway. Before the command starts, the CLI checks that the firewall is dedicated and has no SSH rule. It looks up your public IPv4, writes an access record, and adds a rule for that address as a /32. Then it waits for DigitalOcean to confirm and starts the command. When the command exits, it removes that exact rule and waits for the confirmation again. Then it exits with the command’s own exit status.

That last part matters for agents. On success run prints nothing of its own. The agent sees the remote command’s output and exit code as if it had run ssh directly. When run itself refuses, it prints a JSON object with an error key and exits with 1.

Example 1: check free disk space on the production Droplet

You ask the agent why the deploy failed. It suspects a full disk. Following the rules above, it checks status, sees closed for the production firewall, and runs:

firewall-manager run 3b0f2c1e-8a4d-4e7b-9c51-6f2a1d9e0b37 --minutes 5 -- ssh admin@203.0.113.25 'df -h /'

The output is whatever df prints on your server. No extra lines come from Firewall Manager. Afterwards the agent can check status again, and the firewall is back to closed. If you have the app window open, you’d have seen the access appear and go away, because the app and the CLI share the same records.

The flow, with the points where the agent should stop:

Agent SSH call through Firewall Manager runThe agent checks status, runs one SSH command through firewall-manager run with a time cap, and the rule closes when the command exits or the time runs out. Any refusal sends the agent back to you.NoYesYesNoAgent needs theserverstatus says sshclosed?Stop and show youthe statusrun ID --minutes N-- ssh ...run refused?Rule opens for thisMac's IPv4Command exits ortime runs outRule closes, agentgets the exit code

A second run right after the first starts the cycle again: new record, new rule, new close. Each call waits on DigitalOcean twice, so a dozen tiny commands are slower than one script. Ask the agent to batch read-only checks into one remote command where it can.

Cap how long each call can hold port 22

An agent command can hang. SSH waits for a password prompt nobody answers, a log tail never ends, or a migration takes much longer than expected. Without a cap, the rule stays open for as long as the command runs. run takes the same --minutes option as open, placed before the --. The default is 15, and the range is 1 to 60. When the time runs out, run asks the command to stop, gives it about two seconds, kills it if it’s still running, and closes the rule. The help line for run doesn’t show --minutes, but the docs say run closes at its lease deadline, and the CLI accepts the option.

Example 2: a longer copy with a 30-minute cap

The agent needs to pull a database dump from the server. That takes longer than a df, so the cap goes up:

firewall-manager run 3b0f2c1e-8a4d-4e7b-9c51-6f2a1d9e0b37 --minutes 30 -- scp admin@203.0.113.25:/var/backups/recipes.sql.gz ./backups/

If the copy finishes in four minutes, the rule closes in four minutes. If it’s still going at 30, scp gets stopped and the rule closes anyway. The agent sees a failed command, not a success, and should tell you rather than retry with a bigger number on its own.

Ask for more than an hour and nothing opens:

firewall-manager run 3b0f2c1e-8a4d-4e7b-9c51-6f2a1d9e0b37 --minutes 90 -- ssh admin@203.0.113.25 uptime
{
  "error" : "Choose between 1 and 60 minutes."
}

The same goes for a malformed call. --minutes twenty gives Use --minutes NUMBER and pass commands after --, and a run with nothing after -- gives Pass a local command after --. All three stop before the CLI talks to DigitalOcean.

The rule also closes if the agent’s harness gives up on the command. When run gets Ctrl-C or a terminate signal, it stops the wrapped command, then closes the rule before it exits. The one thing it can’t survive is the Mac itself going away. Sleep, shutdown or a lost connection leave the rule in place until the background cleanup job runs again. That job retries expired access every 15 seconds, but it runs on your Mac, and this version has no timer on DigitalOcean’s side.

Keep the agent away from irreversible commands

Three commands change more than one tracked rule, and they belong to you. block FIREWALL_ID --confirm removes every existing rule for exactly port 22 on that firewall, including ones you added by hand for a reason. auth replaces the token in your Keychain. open is less dangerous, but it leaves the rule up after the agent’s command ends, so you’re back to remembering to close it. Each of these is where a refusal turns into a decision only you should make.

Example 3: the firewall already allows SSH

Someone added an SSH rule in the DigitalOcean control panel last week and forgot it. The agent’s status shows unmanaged. If it runs run anyway, the CLI refuses:

{
  "error" : "This firewall already allows SSH. Close its existing SSH access first."
}

An agent without rules might read “close its existing SSH access” and reach for block --confirm. That’s a destructive step: it deletes rules Firewall Manager didn’t create. With the instructions above, the agent stops and shows you the error. You decide whether that old rule should go. In the app, select the firewall and click Close existing SSH access…, which asks you to confirm first. Do it while you still have another way in, such as the Droplet console. A rule that covers a wider range than port 22 isn’t touched at all. You get A wider port range allows SSH. Review that rule in DigitalOcean; other ports will not be changed here.

The other common refusal is This firewall already has tracked access. Close it before opening again. That usually means you opened SSH from the app for your own session. The agent shouldn’t close it, because that would end your access window, not its own. It should wait for you.

To undo whatever an agent left behind, you run:

firewall-manager close 3b0f2c1e-8a4d-4e7b-9c51-6f2a1d9e0b37

It removes only the exact IP rule Firewall Manager created, and leaves HTTP, HTTPS and outbound rules alone. An SSH session that’s already connected may stay up after the rule goes. To check the close, try a new connection.

If something looks wrong

If the agent gets command not found: firewall-manager, its shell doesn’t have ~/.local/bin on the PATH. Add it in the shell config the agent loads, or choose Install Companion CLI again if the link is missing.

If the agent’s command fails with “The login keychain is locked in this session, which is normal over SSH”, the agent is running in an SSH session into your Mac. Unlock it yourself with security unlock-keychain. Don’t give the agent your login password to do it.

If run says Connect DigitalOcean in Firewall Manager, or use auth --stdin., there’s no token in the Keychain yet. Connect from the app. Don’t paste the token into the agent’s chat.

If run says Use a firewall ID returned by list., the agent passed a name or a truncated UUID. Copy the full id from list into the instructions file.

If run says Another firewall operation is running. Try again in a moment., the app, another agent or the cleanup job holds the lock on the access records. Wait a moment and run it again.

If run says Wait for DigitalOcean to finish its current firewall change., the firewall isn’t settled. Check status until settled is true, then run the command once.

If run says The firewall change is still unconfirmed. Its access record is kept so cleanup can retry., DigitalOcean didn’t confirm in time. Don’t delete leases.json to clear it. Keep the Mac online and check status.

If the app shows Close overdue · retrying after an agent session, the Mac couldn’t finish a close. Restore the connection and check the token in Settings. The cleanup job keeps retrying while the Mac is awake.

Get Firewall Manager

Open DigitalOcean SSH access only for your current IP, with timed access, close-now controls and a companion CLI.

See Firewall Manager → · Read the docs · $20. See the app page for tax details, with full source code.

More tutorials for my apps →

Want me to talk about your product? You can sponsor this site.