# Lock down Claude Code for unattended runs

> For the complete documentation index, see [llms.txt](https://docs-stg.ringleader.dev/llms.txt).


> Set up a workstation so Claude Code can run with nobody watching, holding none of your keys and reaching only the hosts you list.


Set up a workstation so Claude Code can run with nobody watching, holding none of your keys
and reaching only the hosts you list. Use this when Claude Code runs overnight, with nobody there to
stop a command. You first record which hosts the agent uses while you work with it, and then allow
only those.

For another agent, the allowlist, the GitHub token and the deadline work the same way, and
[Run your own coding agent in Ringleader](https://docs-stg.ringleader.dev/guides/run-own-coding-agent/) covers
its key.

## Prerequisites

- [Install Ringleader](https://docs-stg.ringleader.dev/install/), with the Ringleader application running, and
  sign in with `rl auth login`.
- A namespace that Ringleader holds, not `local`. The examples use `acme`. Your organization's
  policies then judge the workstation, as
  [Node-bound workstations](https://docs-stg.ringleader.dev/workstations/basics/#node-bound-workstations)
  describes.
- A GitHub provider that you hold the `use` right on, which an org admin sets up as
  [Connect workstations to GitHub with the Ringleader GitHub App](https://docs-stg.ringleader.dev/guides/connect-github-app/)
  shows. The examples name it `acme-github` and use the repository `acme/web`. With no provider,
  set `userAuthorization: boxOwner` in the first Integration, which reaches every repository you can
  reach. [The credential source](https://docs-stg.ringleader.dev/reference/resources/credentialprovider/#the-credential-source)
  has the fields.
- An Anthropic API key for Claude Code, and a Ringleader deployment that runs the model endpoint.
- No workstation yet. The first task creates one named `my-agent-box`. Replace the name with
  yours.

## Record what the workstation reaches

Create the workstation with an `audit` policy, which records each connection. You build your list
from those records later.

1. Save this as `my-agent-box.yaml`. It names no provider, so the workstation runs on your
   computer's [Default local provider](https://docs-stg.ringleader.dev/workstations/basics/#default-local-provider):

   ```yaml
   apiVersion: workstations.ringleader.dev/v1
   kind: Workstation
   metadata:
     name: my-agent-box
     namespace: acme
     labels:
       role: agent
   spec:
     devtools:
       - name: claude-code
       - name: git
     egress:
       enforcement: audit
   ```

2. Apply the file:

   ```bash
   rl apply -f my-agent-box.yaml
   ```

3. Wait for the workstation:

   ```bash
   rl workstation wait my-agent-box -n acme --for condition=Configured --timeout 20m
   ```

4. Check that recording has started. `status.egress.recorded` lists `allowed` in the output:

   ```bash
   rl workstation get my-agent-box -n acme -o yaml
   ```

<div class="callout callout-warning">
  <p class="callout-title">An audit policy blocks nothing</p>
  <div class="callout-body">
    The workstation can reach any host, your local network included, until you replace the <code>audit</code>
policy below. Do not leave the agent alone before then.
  </div>
</div>


## Keep your keys off the workstation

Ringleader adds the GitHub token and the model key to a request outside the workstation, so no
program in it can read either.

1. Store the model key in a Secret that nobody can read back. Claude Code reaches the model
   through Ringleader's endpoint, which holds the key:

   ```bash
   rl secret create anthropic -n acme --ringleader-only --from-string token=<your-anthropic-key>
   ```

2. Save this as `agent-keys.yaml`. The first Integration adds a GitHub token that reaches only
   `acme/web`. The second points Claude Code at the model endpoint:

   ```yaml
   apiVersion: workstations.ringleader.dev/v1
   kind: Integration
   metadata:
     name: agent-github
     namespace: acme
   spec:
     type: httpProxy
     selector:
       matchLabels:
         role: agent
     httpProxy:
       vendor: github
       credentialSource:
         provider:
           kind: OrgCredentialProvider
           name: acme-github
         repositories: [acme/web]
   ---
   apiVersion: workstations.ringleader.dev/v1
   kind: Integration
   metadata:
     name: agent-claude
     namespace: acme
   spec:
     type: llm
     selector:
       matchLabels:
         role: agent
     llm:
       endpoint:
         source: ringleader
       providers:
         anthropic:
           credentialRef:
             name: anthropic
             key: token
   ```

3. Apply the file yourself, not through someone else. A local workstation gets the GitHub token
   only when its owner is the person who first applied the Integration:

   ```bash
   rl apply -f agent-keys.yaml
   ```

4. Wait until the workstation's network process holds the new rules:

   ```bash
   rl workstation wait my-agent-box -n acme --for=EgressApplied
   ```

5. Open a shell on the workstation and clone the repository, which needs no credential in the
   command:

   ```bash
   rl shell my-agent-box -n acme
   git clone https://github.com/acme/web.git
   ```

Do not forward an SSH key for Git. [Cost of an SSH key](https://docs-stg.ringleader.dev/workstations/connectivity/git-ssh-keys/#cost-of-an-ssh-key)
says why.

## Turn off claude.ai connectors

Claude Code connects the connectors of any claude.ai account signed in on the workstation. This
turns that off, so the agent uses only the MCP servers you declare.

1. Add this inside the existing `spec:` block of `my-agent-box.yaml`:

   ```yaml
   toolconfigs:
     - id: claude-code
       name: claude-code
       config:
         claudeAiConnectors: deny
   ```

2. Apply the file again with `rl apply -f my-agent-box.yaml`.

## Allow only the hosts the agent used

Work with the agent once, then replace the `audit` policy with a `strict` one.

1. In a shell on the workstation, have Claude Code do the kind of task you plan to leave it with.
   A host it does not reach now is missing from your list.
2. Wait 10 minutes for Ringleader to store the connections.
3. On your computer, list what the workstation reached:

   ```bash
   rl workstation egress my-agent-box -n acme --allowed
   ```

4. In `my-agent-box.yaml`, replace the `egress` block with the one below. Its hosts are the ones
   that installing Claude Code and `git` uses. Add each host your task needs, and none you don't
   recognize:

   ```yaml
   egress:
     enforcement: strict
     destinations:
       - host: deb.debian.org    # Debian packages
         ports: [80, 443]
       - host: deb.nodesource.com
       - host: registry.npmjs.org
   ```

   Leave out the hosts in
   [Destinations Ringleader adds](https://docs-stg.ringleader.dev/security/outbound/outbound-restrictions/#destinations-ringleader-adds).
5. Apply the file again.

The workstation then reaches your list and the destinations Ringleader adds, and nothing else.

<div class="callout callout-warning">
  <p class="callout-title">Listed hosts can still receive data</p>
  <div class="callout-body">
    The agent can still send what it reads to any host on the list, to GitHub and to the model
endpoint. DNS lookups also leave the workstation, so data can leave in names.
<a href="https://docs-stg.ringleader.dev/security/model/protection-limits/#connections-a-policy-does-not-stop">Connections a policy does not stop</a>
says more.
  </div>
</div>


## Hold every link for approval

On your computer, run `rl urlopenrules default queue`. Your computer then holds each link that any
workstation asks to open, and drops it if nobody answers within 10 minutes.
[URL open rules](https://docs-stg.ringleader.dev/reference/cli/commands/url-open-rules/) shows how to answer one.

## Set a deadline

Have Ringleader delete the workstation and its disk at a deadline, so a forgotten workstation does
not keep what the agent wrote.

<div class="callout callout-warning">
  <p class="callout-title">The deadline deletes the disk</p>
  <div class="callout-body">
    Push the agent&rsquo;s work to GitHub before the deadline. The <code>ttl</code> counts from when you created the
workstation, so one that has already passed deletes it and its disk at once.
  </div>
</div>


1. Add this inside the existing `spec:` block of `my-agent-box.yaml`, with a `ttl` that outlasts the
   task:

   ```yaml
   lifecycle:
     ttl: 7d
   ```

2. Apply the file again.

## Check the result

Confirm that the settings hold.

1. On your computer, run `rl workstation describe my-agent-box -n acme`. The `EgressEnforced`
   condition reads `True`, and its reason is no longer `Audit`.
2. In a shell on the workstation, request a host that is not on the list, and an address on your
   local network, such as your router's. Both requests fail:

   ```bash
   curl --max-time 5 https://example.com
   curl --max-time 5 http://192.168.1.1
   ```

3. Reach GitHub with no key. The command lists the repository's references:

   ```bash
   git ls-remote https://github.com/acme/web.git
   ```

4. Read the variables the model Integration sets, such as `ANTHROPIC_BASE_URL`. The file holds no
   key:

   ```bash
   cat /etc/ringleader/integrations/agent-claude.json
   ```

## Troubleshoot

- If `rl apply` refuses the workstation,
  [New workstation refused](https://docs-stg.ringleader.dev/troubleshooting/#new-workstation-refused)
  says what to do for each reason.
- If recording has not started,
  [Audit recording](https://docs-stg.ringleader.dev/security/outbound/reach-audit/#audit-recording) says what it
  waits for.
- If the agent cannot reach a host it needs, run `rl workstation egress my-agent-box -n acme`,
  which lists the refused connections. Add the host to the list and apply the file again.
- If `EgressEnforced` reads `False`, do not leave the agent alone.
  [`EgressEnforced` reasons](https://docs-stg.ringleader.dev/reference/resources/workstation/#egressenforced-reasons)
  says what each reason means.
- If the model Integration's status `message` says that your deployment does not run the model
  endpoint, ask whoever runs Ringleader for your organization.
- If `git` asks for a password or GitHub answers `401`, read the **Credential injection**
  section of `rl workstation describe my-agent-box -n acme`. Ringleader renews the token only while
  you are signed in and your computer can reach Ringleader, so sign in with `rl auth login`.
  [Troubleshoot](https://docs-stg.ringleader.dev/guides/connect-github-app/#troubleshoot) lists each reason.
- If that section gives a reason for a host, such as `RingleaderOnly`,
  [Reasons a host is not injected](https://docs-stg.ringleader.dev/reference/resources/integration/#reasons-a-host-is-not-injected)
  says what to do.
- If the workstation stops when you sign out of Windows, lock the PC instead.
  [Keep a workstation running after you sign out](https://docs-stg.ringleader.dev/workstations/providers/windows/#keep-a-workstation-running-after-you-sign-out)
  describes the other choice.

## Next steps

- [Limits of protection](https://docs-stg.ringleader.dev/security/model/protection-limits/)
  says who these settings protect against, and the limits that remain.
- [Workstation reach audit](https://docs-stg.ringleader.dev/security/outbound/reach-audit/) explains what an
  `audit` policy records.
- [MCP servers for coding agents](https://docs-stg.ringleader.dev/workstations/coding-agents/mcp-servers/)
  declares the MCP servers the agent may use.

