> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Lock down Docker and Linux agents

> Run a Docker or Linux agent with a separate identity, limited files, and network access only to a protected OneCLI gateway.

Proxy environment variables only route tools that respect them. An agent can still open a socket directly or remove the variables. To prevent that, use an operating-system network boundary.

These recipes are starting points for an operator-controlled host. Test them with a disposable agent before running untrusted work. They do not protect against a compromised kernel, Docker administrator, or gateway. Read the [known limits](/docs/guides/trust-model.md#known-limits-in-30) first.

## Prepare one agent outside the workload

Use a dedicated vault with only the items this workload needs. Provision a separate agent for each workload. Keep managing keys and connect tokens outside the running agent.

The connection script writes `agent.env` and two trust files beside it. `agent.env` holds the agent's credential and proxy settings, not your stored upstream keys. It has mode `0600`. The file contains absolute certificate paths, so preserve those paths when you mount it into a container.

| File | Contents | Used by |
| - | - | - |
| `gateway-ca.pem` | The gateway's certificate authority alone | `NODE_EXTRA_CA_CERTS`, which adds to Node's own roots |
| `ca-bundle.pem` | The system root certificates, then the gateway's CA | `SSL_CERT_FILE`, `CURL_CA_BUNDLE`, `REQUESTS_CA_BUNDLE`, `GIT_SSL_CAINFO`, `PGSSLROOTCERT`, which replace a trust store |

The bundle keeps public roots in place because a tool that reads those settings trusts only that file. Over an `https` proxy URL it must also trust the gateway's own certificate. The script stops if it finds no system roots, so install `ca-certificates` in the image first.

> [!NOTE]
>
> After a successful request, git passes the proxy credential to its
> credential helper. On macOS with `osxkeychain`, the agent's credential can
> end up in the login keychain. It stops working once you disconnect the
> agent, and it is never an upstream secret. To keep it out, run
> `git config --global credential.helper ""` in the agent's environment.

On a trusted, non-root setup host, prepare a directory for one agent:

```bash theme={null}
set -eu
test "$(id -u)" -ne 0
CONFIG_DIR="$HOME/onecli-agents/research/config"
umask 077
mkdir -p "$CONFIG_DIR"
```

Where you are signed in, make a one-use connect token with `onecli tokens create --vault <vault>`. Download the connection script from your instance's `/v1/install/connect` endpoint and inspect it. Then run it with the token, with `ONECLI_HOME` set to this directory and `ONECLI_PROFILE` set to `"$CONFIG_DIR/profile"`. Those variables keep its files and shell-profile change in the directory you chose. Add `--name research-worker` to give the new agent a recognizable name.

You can instead provision an agent with an explicit expiry in trusted automation and run the script with `--credential` to install that agent's credential. Don't put either credential in an image build argument, Dockerfile, service unit, shared terminal transcript, or source control.

> [!WARNING]
>
> By default a self-hosted proxy URL uses HTTP. Keep the agent-to-gateway
> network private, or [turn on TLS for agents](/docs/self-hosting/configuration.md#tls-for-agents).
> Installing the gateway CA does not encrypt the outer proxy connection.

## Docker: use an isolated gateway network

This example requires Docker Engine and nftables on a Linux host. It uses a self-hosted Compose gateway named `onecli-gateway`. It gives the agent an internal network whose only other container is the gateway. It does not connect the API, database, or dashboard to that network. Don't apply it unchanged to Docker Desktop, where the bridge lives inside a separate VM.

Before starting, build your own `research-agent:3.0` image. It must contain `/bin/sh`, `curl`, a CA trust bundle, and your agent executable at `/opt/agent/bin/run`. The name is an example for your local image, not a OneCLI release image. Use a non-root UID and no setuid tools. Pick an unused subnet if `172.30.40.0/24` overlaps your host or VPN.

**1. Connect only the gateway to the agent network**

Run these commands as the trusted Docker operator:

```bash theme={null}
docker network create --internal --subnet 172.30.40.0/24 \
  --opt com.docker.network.bridge.name=oc-agent-br onecli-agents
docker network connect --ip 172.30.40.2 onecli-agents onecli-gateway
```

The gateway retains its existing service network for upstream access. Reapply this extra network attachment if Compose recreates the gateway container. Stop the workload until its network path is restored.

**2. Block access to the bridge host**

An internal Docker network is not a firewall for services listening on the host's bridge address. Add this separate nftables table on the Docker host before starting the agent:

```nft theme={null}
table inet onecli_agent_host {
  chain input {
    type filter hook input priority 0; policy accept;
    iifname "oc-agent-br" drop
  }
}
```

Save it as `/etc/nftables.d/onecli-agent-host.nft`. Apply it as the host operator:

```bash theme={null}
sudo nft --check --file /etc/nftables.d/onecli-agent-host.nft
sudo nft --file /etc/nftables.d/onecli-agent-host.nft
```

Persist this table with your host firewall. It blocks connections from the agent bridge to the host, not requests forwarded between the agent and gateway containers.

**3. Check the generated proxy destination**

On the setup host, check the endpoint without printing the credential:

```bash theme={null}
(
  . "$CONFIG_DIR/agent.env"
  case "$HTTPS_PROXY" in
    http://x:oc_agent_*@gateway:10255) printf 'Proxy endpoint matches\n' ;;
    *) printf 'Configure the agent proxy address as gateway:10255 before provisioning\n' >&2
       exit 1 ;;
  esac
)
```

For this recipe, your instance must advertise `gateway:10255` as `ONECLI_AGENT_PROXY_ADDRESS` when you provision the agent. Don't rewrite a credential-bearing URL by pasting it into a shell history.

**4. Start the workload without host privileges**

Create a workspace containing only the files the agent may change. Run from its parent directory:

```bash theme={null}
mkdir -p work
WORK_DIR="$(pwd)/work"
docker run --rm --name research-agent \
  --network onecli-agents \
  --add-host gateway:172.30.40.2 \
  --dns 127.0.0.1 \
  --user "$(id -u):$(id -g)" \
  --cap-drop ALL \
  --security-opt no-new-privileges:true \
  --read-only \
  --pids-limit 256 --memory 1g --cpus 2 \
  --tmpfs /tmp:rw,nosuid,nodev,size=128m,mode=1777 \
  --mount "type=bind,src=$CONFIG_DIR,dst=$CONFIG_DIR,readonly" \
  --mount "type=bind,src=$WORK_DIR,dst=/work" \
  --env "ONECLI_HOME=$CONFIG_DIR" --env HOME=/work \
  --workdir /work \
  --entrypoint /bin/sh research-agent:3.0 \
  -c '. "$ONECLI_HOME/agent.env" && exec /opt/agent/bin/run'
```

Keep Docker's default seccomp profile. Don't add `--privileged`, host networking, extra networks, devices, or a Docker socket mount. The explicit host entry lets the proxy resolve without giving the agent an external DNS resolver. The gateway resolves upstream names.

The read-only config mount contains a credential for this agent. Never replace it with the instance `.env`, your home directory, or the gateway data volume.

## Linux: use a dedicated account and outbound firewall

Use a dedicated unprivileged account, not your personal login. Give it a private home, no `sudo` access, and no supplementary groups that control containers or the host. Install the agent and its connection files as that account. Keep the gateway on a protected, reachable private address.

This example assumes the account has UID `20000` and the gateway is `10.20.0.10:10255`. Replace those with your assigned UID and private address. Add a root-owned host entry for the proxy name, for example `10.20.0.10 gateway`, so this account needs no outbound DNS. Provision it with that proxy address before applying the firewall.

### Restrict outbound connections

Apply a dedicated nftables table as root on the Linux agent host. It only narrows the dedicated account's outbound traffic. It does not replace your existing firewall. Don't apply it on the gateway host using the gateway service's UID.

```nft theme={null}
 table inet onecli_agent_egress {
   chain output {
     type filter hook output priority 0; policy accept;
     meta skuid 20000 ip daddr 10.20.0.10 tcp dport 10255 accept
     meta skuid 20000 reject
   }
 }
```

Save this as `/etc/nftables.d/onecli-agent.nft`. Check syntax before applying it:

```bash theme={null}
sudo nft --check --file /etc/nftables.d/onecli-agent.nft
sudo nft --file /etc/nftables.d/onecli-agent.nft
```

The final rule also rejects IPv6 traffic for that UID. If you intentionally use IPv6 for the gateway, add one equally narrow IPv6 destination and port rule before the reject. Your existing firewall must also allow the connection and its reply. Persist the table using your distribution's firewall configuration, then test it again after reboot.

### Restrict the service

Run the workload under a systemd service with a small writable state directory. For example, use `/var/lib/research-agent` as the account's home and provision its files at `/var/lib/research-agent/.config/onecli`. The account and directory must exist before you start the service.

```ini theme={null}
[Unit]
Description=Research agent through OneCLI
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=research-agent
Group=research-agent
Environment=HOME=/var/lib/research-agent
WorkingDirectory=/var/lib/research-agent
ExecStart=/bin/sh -c '. /var/lib/research-agent/.config/onecli/agent.env && exec /opt/agent/bin/run'
NoNewPrivileges=yes
CapabilityBoundingSet=
AmbientCapabilities=
ProtectSystem=strict
ProtectHome=yes
PrivateTmp=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectControlGroups=yes
RestrictSUIDSGID=yes
ReadWritePaths=/var/lib/research-agent
LimitCORE=0
TasksMax=256
MemoryMax=1G
UMask=0077

[Install]
WantedBy=multi-user.target
```

Save it as `/etc/systemd/system/research-agent.service`. Confirm that `research-agent` really has UID `20000`, matching the firewall rule. Validate the unit before starting it:

```bash theme={null}
id research-agent
sudo systemd-analyze verify /etc/systemd/system/research-agent.service
sudo systemctl daemon-reload
sudo systemctl start research-agent.service
```

The service restrictions are not an egress firewall. Keep the UID-based network rules in place. Don't run a second workload under that UID or let this account change its UID.

## Test the boundary

Run these checks inside the same container or service context as the agent, before replacing a test workload with the real one:

| Check | Required result |
| - | - |
| Normal HTTPS request through the configured proxy to a non-echoing test upstream | Succeeds only with the vault permission you intended. |
| Same request with all proxy variables removed, using a known public IP and `curl --noproxy '*'` | Cannot connect. |
| Direct request to the API, database, dashboard, or a metadata address | Cannot connect. |
| Direct IPv6 request | Cannot connect unless you explicitly allowed that gateway destination. |
| DNS lookup to an external resolver | Cannot reach the resolver. |
| Read of a host file outside the mounted workspace or service paths | No sensitive host file is available. |
| Access to Docker socket, privileged devices, or a root shell | Not available. |
| Request using an item set to **Never** | No credential use succeeds. |

Use explicit connection timeouts for network checks. Test again after a reboot or container recreation. If direct egress succeeds, stop the workload and fix the network boundary. Proxy variables alone are not a safe fallback.

## Next steps

* [Harden the OneCLI server](/docs/self-hosting/hardening.md).
* [Review the trust and threat model](/docs/guides/trust-model.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.