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

# A Docker AI workflow

> Read the daemon's real state, have a local model explain it, keep the report — with the exec boundary pinned to argv form and default-deny permits.

Ops work is where « the agent ran a command » stops being acceptable and
« the file says exactly which commands, and the runtime enforces it »
starts to matter. This guide builds a Docker health report the audited
way: two pinned `docker` reads, one local model, one kept artifact.

## The whole workflow

`nika check` passes it on `nika {STATUS.version}` (exit 0 · permits
declared · 0 hints). Save it as `docker-health-report.nika`:

```yaml theme={"system"}
# EXEC LEDGER ·
# | task | command          | why no native path               | unlock that removes it |
# | ps   | docker ps        | product CLI · no MCP surface yet | a docker MCP server    |
# | df   | docker system df | same                             | same                   |
# read the Docker daemon's state, have a local model explain it, keep the report
nika: docker-health-report

model: ollama/qwen3.5:4b

permits:
  exec:
    - "docker"
  tools:
    - "nika:write"
  fs:
    write:
      - "./docker-health.md"

tasks:
  ps:
    exec:
      command: ["docker", "ps", "--all", "--format", "{{.Names}}\t{{.Status}}\t{{.Image}}"]

  df:
    exec:
      command: ["docker", "system", "df"]

  diagnose:
    with:
      containers: ${{ tasks.ps.output }}
      disk: ${{ tasks.df.output }}
    infer:
      prompt: |
        You are reading a Docker host's state. Containers (name·status·image):
        ${{ with.containers }}

        Disk usage:
        ${{ with.disk }}

        Write a short health report: what is running, what exited, what
        looks unhealthy (restart loops · old exits), and whether disk
        usage needs attention. Plain prose, no preamble.
      max_tokens: 600

  keep:
    with:
      report: ${{ tasks.diagnose.output }}
    invoke:
      tool: "nika:write"
      args:
        path: "./docker-health.md"
        content: "${{ with.report }}"

outputs:
  report: ${{ tasks.keep.output }}
```

## Why the exec tasks are arrays

Write `shell: "docker ps | grep Up"` and `nika check` refuses to bless
the boundary:

```text theme={"system"}
 ✖ PERMITS  [NIKA-SEC-004 · exec] task `ps` · a shell-string command cannot be verified against a `permits.exec` program allowlist (a pipeline can launch any program) — use the array form
 ↳ HINT     [native-first/006] `grep` has an exact native form — a recursive regex search is `nika:grep` — returns `{path,line,match}` sorted, already structured
```

That refusal is the feature. A shell string can smuggle any program
through a pipe; the **argv array** names exactly one program with exactly
those arguments, so `permits.exec: ["docker"]` is a boundary the checker
can actually prove. Transforms that would have lived in `| grep | awk`
belong in `extract:` bindings and `nika:jq` instead.

## What the audit says before a token is spent

```text theme={"system"}
nika check · docker-health-report.nika
 ✔ PLAN     3 waves · 4 tasks · max parallelism 2
      wave 1 ps (exec · docker) · df (exec · docker)
      wave 2 diagnose (infer · ollama/qwen3.5:4b)
      wave 3 keep (invoke · nika:write)
 ✔ ACCESS   ollama/qwen3.5:4b → ollama (local · local · declared) · present · liveness judged at run
 ⚠  COST     bounded portion $0.0000 no total ceiling · 1 unpriced task · prompts, exec + mcp unpriced · prices 2026-10-12
   diagnose  ollama/qwen3.5:4b  UNBOUNDED — no catalog price (local model; spend not metered)
 ✔ ORDER    no exec: sits downstream of a net-effecting task · unauthored content never reaches a shell
 ✔ PERMITS  literal + const: args fit the boundary · computed programs, paths + symlinks are the RUN's verdict · exec outside the fs bounds
 ⚠ audited · 4 tasks · 3 waves · permits exec:docker tools:nika:write write:./docker-health.md · est unbounded · 1 unpriced task · 0 hints · risk unbounded — no dollar meter for a local/unknown model · cap a cloud seat on the run: `nika run <file> --max-cost-usd <usd>`
 layers · valid ✔ · access ready ✔ · capacity fit ✔ · run ready ✔
```

<sub>Captured from `nika {STATUS.version}`; the rows that only say ✔ for checks this file does not exercise are left out.</sub>

Two things worth noticing:

* The two `docker` reads run **in parallel** (wave 1) — the scheduler
  proved it from the `with:` bindings, nobody ordered it.
* The cost line practices the honesty rule: a local model is **unpriced
  compute, not « free »** — the report says the total has no ceiling and
  names why (no catalog price for a local model); it never rounds unknown
  to \$0.

## Run it

```bash theme={"system"}
nika run docker-health-report.nika
```

With the Docker daemon up and a local model served, the card lists the two
`docker` reads side by side (`∥`, the same wave), then the model call, which
takes as long as your model needs, then the write. The total reads
**unpriced**, never `$0.00`: nothing in the catalog can meter a model on your
own machine. Rehearse the whole file first with
`nika run docker-health-report.nika --model mock/echo`: the `docker` reads run
for real and the mock echoes the prompt instead of calling a model.

`docker-health.md` then holds the model's prose, and the run left a
hash-chained journal you can prove later:

```bash theme={"system"}
nika trace verify .nika/traces/<run>.ndjson
```

## When the daemon is down

The failure is part of the design. With Docker stopped, the same run
fails **honestly and early** — the model is never called, nothing is
spent, and the card hands over. Captured on `nika {STATUS.version}`:

```text theme={"system"}
$ nika run docker-health-report.nika --model mock/echo
  🦋 nika · docker-health-report · 4 tasks
     permits ✓ declared boundary · exec outside the fs bounds

  ✖  ps        exec · docker · untrusted input from ps  111ms
  ✖  df        exec · docker · untrusted input from df  107ms ∥
  ⊘  diagnose  blocked · ps settled failed · no binding here admits that
  ⊘  keep      blocked · diagnose settled blocked · no binding here admits that
  4 tasks · 3 waves · 0 retries
  ── 4/4 done · 2 failed · 2 blocked · unmetered · elapsed 0.1s ──
    wrote .nika/traces

  ✖ NIKA-EXEC-001 · command exited with status 1: failed to connect to the docker API at unix:///var/run/docker.sock; check if the path is correct and if the daemon is running: dial unix /var/run/docker.sock: connect: no such file or directory

    fix: nika explain NIKA-EXEC-001
```

## Take it further

* **Gate an action on the report** — add an `agent:` task allowed only
  `nika:done`, or a `when:` gate on a structured `diagnose` output, and
  the workflow can *act* on unhealthy containers, still inside the
  declared boundary. See [patterns](https://docs.nika.sh/guides/patterns.md).
* **Schedule it** — the file is the artifact: cron or CI runs
  `nika run`; when journaling is enabled, inspect and verify the evidence
  the execution leaves behind.
* **Structured instead of prose** — give `diagnose` a `schema:` and the
  report becomes typed data downstream tasks can branch on. See
  [testing](https://docs.nika.sh/guides/testing.md) for pinning it with a golden.

> [!NOTE]
>
> The two `exec` tasks carry the repo's **exec ledger** (the header
> comment): every surviving `exec:` names why no builtin or MCP tool
> covers it yet, and what would remove it. When a Docker MCP server enters
> your stack, `invoke:` replaces both reads and the ledger empties —
> that is the [native-first law](https://docs.nika.sh/concepts/workflows.md) working as intended.


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