# Run a coding agent

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


> Add the OpenCode coding agent to a running workstation, connect it to OpenRouter with your key, then give the agent a task.


Add the OpenCode coding agent to a running workstation, connect it to OpenRouter with
your key, then give the agent a task.

The agent works inside the workstation, so it sees
the files and tools you put there and none of the files on your own computer. It never
sees your key: Ringleader adds the key to its requests after they leave the workstation.

## Prerequisites

- [Ringleader installed](https://docs.ringleader.dev/install/), with the Ringleader
  application running.
- The `my-opencode-box` workstation from
  [Build a workstation](https://docs.ringleader.dev/quickstart/workstation/), running Debian 13
  with the label `role: agent`.
- An [OpenRouter API key](https://openrouter.ai/settings/keys). A free OpenRouter
  account is enough.

## Understand workstations and configurations

Ringleader keeps a workstation, what goes on it, and the services it uses in separate
resources:

- A [Workstation](https://docs.ringleader.dev/reference/resources/workstation/) is the workstation
  itself. `my-opencode-box` is one.
- A [WorkstationConfig](https://docs.ringleader.dev/reference/resources/workstationconfig/) is a set of
  contents and settings you can reuse: packages, development tools, ports, environment
  variables, and more.
- An [Integration](https://docs.ringleader.dev/reference/resources/integration/) connects workstations to an
  outside service, such as OpenRouter, and adds the key the service needs, which it reads
  from a secret.

One configuration can apply to many workstations, and one workstation can take several
configurations.

A configuration finds its workstations by label. This page uses the `role: agent` label
you gave `my-opencode-box` on the previous page, so the configuration reaches every
workstation that carries it, without editing each one.

## Store your key

Save your OpenRouter key in Ringleader as a secret called `openrouter-api-key`.


### Use the application


Run this command:

```bash
rl secret create openrouter-api-key -n local --from-string value=<your-openrouter-key>
```



### Use the command line


Run:

```bash
rl secret create openrouter-api-key -n local --from-string value=<your-openrouter-key>
```

Ringleader keeps the value and masks it wherever it shows the secret. The integration
you write next refers to the secret by name, so the key never appears in a file.






## Add OpenCode to the workstation

Add a configuration that installs OpenCode, and an integration that adds your key to
OpenCode's requests.


### Use the application


Use the **Use the command line** tab.



### Use the command line


Create a file called `opencode.yaml` with a configuration and an integration. Both have a
`selector` that matches the `role: agent` label on `my-opencode-box`:

```yaml
apiVersion: workstations.ringleader.dev/v1
kind: WorkstationConfig
metadata:
  name: opencode
  namespace: local
spec:
  selector:
    matchLabels:
      role: agent
  devtools:
    - name: nodejs
    - name: opencode
  environment:
    OPENROUTER_API_KEY: not-the-real-key
---
apiVersion: workstations.ringleader.dev/v1
kind: Integration
metadata:
  name: openrouter
  namespace: local
spec:
  type: httpProxy
  selector:
    ownerScope: true
    matchLabels:
      role: agent
  httpProxy:
    rules:
      - host: openrouter.ai
        inject:
          header: Authorization
          value: "Bearer ${secret:openrouter-api-key/value}"
```

The first part of the file, the `WorkstationConfig`, says what to put on the workstation:

- `selector.matchLabels` picks the workstations the configuration applies to: every one
  labeled `role: agent`, which includes `my-opencode-box`.
- `devtools` installs Node.js and OpenCode. OpenCode installs through npm, which comes
  with Node.js.
- `environment` sets `OPENROUTER_API_KEY` to a stand-in, `not-the-real-key`, because
  OpenCode needs a value there before it sends a request.

The second part, the `Integration`, gives OpenCode access to OpenRouter:

- `type: httpProxy` means Ringleader adds a key to requests as they leave the
  workstation.
- `selector` picks the workstations the integration reaches. `ownerScope: true` limits
  it to workstations you own, and `matchLabels` narrows that to the ones labeled
  `role: agent`.
- `rules` says which requests get the key. On each request to `openrouter.ai`,
  Ringleader replaces the `Authorization` header with `Bearer` and the value of your
  `openrouter-api-key` secret, so the stand-in never reaches OpenRouter.

Apply the file:

```bash
rl apply -f opencode.yaml
```

Ringleader installs the tools on the running workstation. It does not rebuild it, so
the files you left there are still there.

Wait until the tools are installed, then until Ringleader is adding your key to
requests:

```bash
rl workstation wait my-opencode-box --for condition=Configured --timeout 15m -n local
rl workstation wait my-opencode-box --for=EgressApplied --timeout 5m -n local
```






## Give OpenCode a task

Open a shell on the workstation. In the application, click the terminal button on its
card. On the command line, run `rl shell my-opencode-box -n local`. Then check which key
the workstation holds:

```bash
echo $OPENROUTER_API_KEY
```

The output is `not-the-real-key`. Start OpenCode:

```bash
opencode
```

In OpenCode, type `/models` and choose an OpenRouter model. A free model is enough for
this task. Then give the agent its task:

```text
Create hello.py that prints today's date, then run it.
```

OpenCode writes `hello.py` and runs it. If it asks before it runs a command, allow it.
When you are done, leave OpenCode, then type `exit` to leave the shell.

And you're done! You have a coding agent working in a workstation of its own.

## Understand what happened

Applying `opencode.yaml` added the `opencode` configuration and the `openrouter`
integration. Their selectors matched the `role: agent` label on `my-opencode-box`, so
Ringleader installed Node.js and OpenCode on it and started adding your key to its
requests to OpenRouter.

<div class="callout callout-note">
  <p class="callout-title">How your key reached OpenRouter</p>
  <div class="callout-body">
    <ol>
<li><code>rl secret create</code> stored your key in Ringleader, under the name
<code>openrouter-api-key</code>.</li>
<li>The integration refers to that secret by name, as
<code>${secret:openrouter-api-key/value}</code>, so the key is in none of your files.</li>
<li>OpenCode sent each request to <code>openrouter.ai</code> with the stand-in key,
<code>not-the-real-key</code>, in its <code>Authorization</code> header.</li>
<li>As each request left <code>my-opencode-box</code>, Ringleader replaced that header with
<code>Bearer</code> and your real key, and sent the request on to OpenRouter.</li>
</ol>
<p>Nothing running in the workstation can read your key, the agent included. Ringleader holds
the key on your computer, outside the workstation. To see what Ringleader adds to which requests, and on which providers it
works, see <a href="https://docs.ringleader.dev/security/credentials/injected-credentials/">Injected credentials</a>. To see what else
changes on a workstation once Ringleader adds a key, see
<a href="https://docs.ringleader.dev/security/credentials/injection-effects/">Effects of injection on a workstation</a>.</p>
  </div>
</div>


## Optional: Clean up

Remove the configuration, the integration, the workstation and the secret that this
quickstart created. Skip this section to keep using the workstation and its agent.


### Use the application


On the workstation's card, open the menu, choose **Delete**, and type `my-opencode-box`
to confirm.

Remove them from the command line. Type `y`
when `rl` asks you to confirm deleting the secret:

```bash
rl workstation delete -f opencode.yaml
rl secret delete openrouter-api-key -n local
```



### Use the command line


Delete the configuration and the integration, then the workstation, then the secret:

```bash
rl workstation delete -f opencode.yaml
rl workstation delete my-opencode-box -n local
rl secret delete openrouter-api-key -n local
```

With `-f`, `rl workstation delete` deletes everything the file declares, so the first
command removes both the configuration and the integration. The other two commands ask
you to confirm: type `y` each time.






## Summary

Ringleader gave the agent a workstation that is secure, consistent and isolated:

- Your key stays secure. The workstation holds only `not-the-real-key`, so the agent
  can't print your key or send it anywhere.
- Your setup stays consistent. The workstation's own description and `opencode.yaml` say
  everything that is on it. Apply them on another computer, or give them to a teammate who
  stores their own key, and you get the same workstation. Label another workstation you
  own `role: agent` and it gets the same tools and the same access to OpenRouter.
- The agent stays isolated. It works inside `my-opencode-box`, so it sees only the files
  and tools you put there, and none of the files, repositories or credentials on your own
  computer. When you delete the workstation, its disk goes with it, along with every
  file the agent left there.

## Next steps

- [Coding agent setup](https://docs.ringleader.dev/workstations/coding-agents/coding-agent-setup/)
  says what each agent comes with, and how to start and sign in to it.
- [LLM gateways for coding agents](https://docs.ringleader.dev/workstations/coding-agents/llm-gateways/)
  points the coding agents on every workstation you label at an LLM gateway.
- [Stacks](https://docs.ringleader.dev/workstations/packages-tools-settings/stacks/) create a ready-made
  workstation with the tools and agent for one kind of work.
- [Lock down Claude Code for unattended runs](https://docs.ringleader.dev/guides/lock-down-claude-code/)
  keeps your keys and your local network away from Claude Code, and sets a date when the workstation deletes itself.
- [Run your own coding agent in Ringleader](https://docs.ringleader.dev/guides/run-own-coding-agent/)
  keeps an agent's key off the workstation for any agent that sends it in a header.
- [Run VS Code in a browser on a workstation](https://docs.ringleader.dev/guides/run-vscode-in-browser/) builds a
  workstation with VS Code in your browser.

