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

> ## Agent Instructions
> Setting OneCLI up for your person? Follow https://onecli.sh/docs/quickstart.md. Never ask for or accept a key, token or password in the chat: OneCLI needs none.
> No OneCLI credential? Run `onecli connect`, or follow https://onecli.sh/auth.md. A person approves every new agent in their browser.
> Already connected? `onecli status`, `onecli items` and `onecli check <METHOD> <URL>` tell you what you can use. Full guide: https://onecli.sh/skill.md
> Search these docs over MCP at https://onecli.sh/docs/mcp. Report a wrong or unclear page with its `submit_feedback` tool.

# Connect Docker, a server or CI

> Connect an agent in a Docker container, on a Linux server, or in a CI job to a OneCLI vault with a one-use connect token and one shell line.

An agent in a container, on a server, or in a CI job connects to one vault with a one-use connect token. You make the token where you are signed in, then run one line where the agent runs. That place gets its own agent credential and proxy settings, never your key and never a stored secret. The gateway adds the secret to each call on the way out.

You need `onecli` 3.4 or later where you make the token, signed in with `onecli login`. The place you connect needs only `sh` and `curl`. See the [Quickstart](https://onecli.sh/docs/quickstart.md).

## Make a connect token

Find the vault the agent should use:

```bash theme={null}
onecli vaults list
```

```json theme={null}
[
  {
    "id": "lhnojmifhyjqyshv",
    "name": "Personal",
    "slug": null,
    "personal": true,
    "item_count": 1,
    "agent_count": 0,
    "created_at": "2026-11-30T12:10:44.512Z",
    "last_used_at": null,
    "member_count": 1
  }
]
```

Make a token. Name the agent so you can tell your agents apart, and name the provider, such as `docker` or `aws-ec2`:

```bash theme={null}
onecli tokens create --vault lhnojmifhyjqyshv --name research-container --provider docker
```

```json theme={null}
{
  "id": "605ba657-1c5c-423f-ab62-7cfdf98751dd",
  "vault_id": "lhnojmifhyjqyshv",
  "name": "research-container",
  "provider": "docker",
  "created_at": "2026-12-01T14:58:22.013Z",
  "expires_at": "2026-12-01T15:13:22.004Z",
  "connect_token": "oc_connect_…",
  "connect_command": "onecli connect oc_connect_…",
  "install_command": "curl -fsSL https://api.onecli.sh/v1/install/connect | sh -s -- oc_connect_…"
}
```

The token works once, and expires after 15 minutes unless you pass `--expires-in` (`1m` to `60m`). It is a credential: pass it only to the place it is for, and don't log or save it.

Use `install_command` where `onecli` is not installed. Use `connect_command` where it is. Run either one as the user the agent runs as. It writes `agent.env` (mode `0600`) with the agent's credential and proxy settings, and a line in the shell profile that reads it.

## Docker

Run `install_command` inside the running container:

```bash theme={null}
docker exec research-container sh -c '<install_command>'
```

Put the whole `install_command` in place of `<install_command>`, as it is. The script sees it runs in a container and records the agent's runtime as `docker`.

If you self-host OneCLI on the same machine at a `localhost` address, the container reaches it through `host.docker.internal`. Start the container with `--add-host=host.docker.internal:host-gateway` when it cannot resolve that name.

Proxy settings only route tools that respect them. To make the gateway the container's only way out, see [Lock down Docker and Linux agents](https://onecli.sh/docs/guides/agent-lockdown.md).

## Your own server

Open a shell on the server, as the user the agent runs as, and run `install_command` there. For example over SSH:

```bash theme={null}
ssh deploy@build-01.example.com
curl -fsSL https://api.onecli.sh/v1/install/connect | sh -s -- oc_connect_…
```

A new login shell reads `agent.env`, so start the agent from one, such as a new SSH session. For a systemd service, read `agent.env` in `ExecStart`, as in the [Linux lock-down recipe](https://onecli.sh/docs/guides/agent-lockdown.md#restrict-the-service).

## CI

A CI runner that stays up, such as a self-hosted runner, is a server: connect it once, as above, and its jobs read `agent.env`.

A job on a fresh runner cannot use a connect token, because a token works once. Give CI its own agent instead. Its credential (`oc_agent_...`) reaches one vault and can only call APIs through the gateway. Never put your managing key in CI: it manages every vault you can use.

**1. Make the CI agent once, on your own machine**

Use a vault that holds only the items CI needs. Make the agent with the managing key `onecli login` saved, and give it an expiry. We recommend 30 days, so a leaked credential stops on its own. The API takes 5 minutes to 90 days.

```bash theme={null}
curl -sS https://api.onecli.sh/v2/agents \
  -H @<(printf 'Authorization: Bearer %s\n' "$(cat ~/.onecli/credentials/api-key)") \
  -H "Content-Type: application/json" \
  -d "{\"vaultId\":\"krhfdidgdklvzgkh\",\"name\":\"ci-release\",\"provider\":\"github-actions\",\"runtime\":\"linux\",\"expiresAt\":\"$(date -u -v+30d +%Y-%m-%dT%H:%M:%SZ)\"}" \
  | jq -r .credential | gh secret set ONECLI_AGENT_CREDENTIAL
```

On Linux, use `date -u -d '+30 days' +%Y-%m-%dT%H:%M:%SZ`. The key goes to `curl` as a header file, so it is not in the command line other users on the machine can list. The answer holds the credential once. The pipe stores it straight in a CI secret, so it never shows on screen. The answer also holds the agent's `id`, `vaultId`, `expiresAt` and `gateway`.

**2. Connect in the job**

Run the connection script with the credential instead of a token. It writes `agent.env` and the gateway certificate:

```yaml theme={null}
- name: Connect to OneCLI
  env:
    ONECLI_AGENT_CREDENTIAL: ${{ secrets.ONECLI_AGENT_CREDENTIAL }}
  run: curl -fsSL https://api.onecli.sh/v1/install/connect | sh -s -- --credential "$ONECLI_AGENT_CREDENTIAL"
- name: Run the agent
  run: sh -lc './scripts/run-agent.sh'
```

A login shell reads `agent.env`, so the agent's calls go through the gateway.

**3. Replace it before it expires**

When the agent reaches its `expiresAt`, its calls answer `401`. Make a new one as in the first step, and disconnect the old one with `onecli agents disconnect <agent-id> --yes`.

With `CI` set, `onecli` never asks a question and never updates itself.

## Check the agent is connected

```bash theme={null}
onecli agents list --mine
```

```json theme={null}
[
  {
    "id": "3a7c9e1f-5b2d-4c8a-b6e4-0f9d2a1c7b35",
    "name": "research-container",
    "vault_id": "lhnojmifhyjqyshv",
    "runtime": "docker",
    "provider": "docker",
    "status": "active",
    "created_at": "2026-12-01T15:01:47.326Z",
    "expires_at": null,
    "last_seen_at": "2026-12-01T15:01:47.326Z",
    "created_by": {
      "via": "connect",
      "person": "Dana Levi",
      "key_name": "onecli login on a terminal"
    },
    "kind": null,
    "vault_name": "Personal"
  }
]
```

Then make the same call twice where the agent runs. Around OneCLI, it answers `401`:

```bash theme={null}
curl --noproxy '*' -s -o /dev/null -w "%{http_code}\n" https://httpbin.org/bearer
```

Through OneCLI, it answers `200`, because the gateway added the Test key. A login shell reads the proxy settings:

```bash theme={null}
sh -lc 'curl -s -o /dev/null -w "%{http_code}\n" https://httpbin.org/bearer'
```

In a container, run each one with `docker exec research-container sh -lc '...'`.

## When something fails

| What you see | What to do |
| - | - |
| `curl is needed and was not found.` | Install `curl` in the image or on the server, then run the line again. |
| `This container cannot reach OneCLI on the host.` | Start the container with `--add-host=host.docker.internal:host-gateway`. |
| The agent is not in `onecli agents list --mine` | The line did not run, or the token expired. Make a new token and run its line again. |
| `401` through OneCLI | The vault has no item for this host. Add one to the vault in the dashboard. |

## Next steps

* [Lock down Docker and Linux agents](https://onecli.sh/docs/guides/agent-lockdown.md)
* [Connect an agent in a sandbox](https://onecli.sh/docs/guides/sandboxes)
* [Disconnect an agent or revoke a token](https://onecli.sh/docs/cli/onecli-cli.md#agents)


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