Skip to content
Esc
↑↓navigate↵open⌘Jpreview
Start
On this page

Runbook Automation

Write runbooks Autohand can follow, start runs from your alerting or scheduler, and keep every change behind permissions, patches and human review.

Overview

Runbooks encode your operational knowledge. Rather than relying on engineers to remember steps during a high-pressure incident, you can have Autohand read the runbook, gather the facts and carry out or propose each step.

Autohand Code CLI has no runbook engine, runbook file format or sre command. You build runbook automation from general pieces:

  • Runbooks: plain Markdown files in your repository that both people and Autohand read
  • Triggers: your alerting system, CI or scheduler starts a headless run (autohand -p)
  • Actions: Autohand runs the commands the runbook names, or writes infrastructure-as-code changes as a patch
  • Safeguards: permission rules, --restricted, --dry-run, run budgets and hooks
  • Rollback: steps written in the runbook, plus git: changes made as patches or in a worktree are easy to discard

Runbook structure

Write each runbook as Markdown in a runbooks/ directory. State the trigger, the checks, the actions with their limits, and when to stop and hand over to a person:

# runbooks/disk-pressure.md

Trigger: disk.used_percent above 85% for 10 minutes on a production host.

## Checks
1. Run `df -h` and `du -sh /var/log/* | sort -rh | head -10`.
2. Report which directories grew since the last deploy.

## Actions
1. If usage is above 90%, propose deleting `*.log` files in /var/log older
   than 7 days. List the files and their total size first.
2. If usage is above 95%, change `volume_size` in `infra/storage/ebs.tf` to
   1.5x the current size. Make this change as a patch only.

## Limits
- Never delete files outside /var/log.
- Never run `terraform apply`. The infra pipeline applies reviewed changes.
- Stop and page a person if the checks do not explain the growth.

## Rollback
- Log deletion cannot be undone. Confirm the file list before step 1.
- Revert the Terraform patch with `git revert` if the plan is wrong.

Mention the runbook directory in your AGENTS.md so interactive sessions find it. With --bare, AGENTS.md is not loaded; name the runbook in the prompt or pass it with --append-system-prompt-file.

Triggers

Autohand does not watch metrics, logs or schedules. Keep detection in the tools that already do it, and have them start a run.

Alert and metric triggers

Configure Alertmanager, PagerDuty, Opsgenie or Datadog to call a webhook. The handler (a small service or a CI job) saves the payload and runs Autohand headlessly:

cat alert.json \
  | autohand --bare --ephemeral -p "Using runbooks/disk-pressure.md, triage this alert. Report the likely cause and the next step; do not take any action." \
      --restricted --max-duration 300

--restricted denies every operation that would need approval, including shell commands, so this run works only from the piped data and the files in the repository. Have the handler collect the output of the runbook’s check commands and pipe it in too, or allow specific commands with --allowed-tools (see Actions).

Log pattern triggers

Use your log platform’s alerting (for example a Loki ruler rule or a CloudWatch metric filter and alarm) to fire the same webhook when a pattern such as OutOfMemoryError appears.

Scheduled triggers

Run maintenance runbooks from cron or a CI schedule. This GitHub Actions job runs every Sunday at 02:00 UTC:

on:
  schedule:
    - cron: "0 2 * * 0"

jobs:
  weekly-maintenance:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: curl -fsSL https://autohand.ai/install.sh | sh
      - run: |
          autohand --bare -p "Follow runbooks/weekly-cert-check.md and report certificates that expire within 14 days." \
            --allowed-tools "read_file,find_grep,run_command(openssl:*)" --max-duration 600
        env:
          AUTOHAND_PROVIDER: ${{ secrets.AUTOHAND_PROVIDER }}
          AUTOHAND_API_KEY: ${{ secrets.AUTOHAND_API_KEY }}
          AUTOHAND_AI_API_KEY: ${{ secrets.AUTOHAND_AI_API_KEY }}

See Headless mode for the credential variables --bare reads.

Actions

Autohand carries out runbook steps with its normal tools. It runs shell commands with run_command and shell, and edits files with write_file and the other file tools. There are no action types to declare. The runbook text says what to run, and your permission settings decide what is allowed.

Commands and Kubernetes

For steps that run commands, start an interactive session so an engineer approves each command as Autohand proposes it:

autohand --worktree inc-1234
# Then: "Follow runbooks/pod-restart-loop.md for deployment api-server in namespace production."

To limit a headless run to the tools a runbook needs, use --allowed-tools. This run can read files and run kubectl, and nothing else:

autohand -p "Follow the checks in runbooks/pod-restart-loop.md for deployment api-server in namespace production." \
  --allowed-tools "read_file,find_grep,run_command(kubectl:*)" \
  --max-duration 300

Combine this with a permissions.denyList entry such as "run_command:kubectl delete:*" and its "shell:kubectl delete:*" twin (see Safeguards) so destructive subcommands stay blocked.

Terraform and other infrastructure as code

For persistent changes, have Autohand edit the Terraform, Helm or Kubernetes manifests and produce a patch. Nothing changes until the patch goes through your normal review and pipeline:

cat alert.json \
  | autohand -p "Follow step 2 of runbooks/disk-pressure.md for this alert." \
      --disallowed-tools run_command,shell --patch --output disk-pressure.patch

API calls

Steps that call an API, such as turning off a feature flag, work best through an MCP server for that service (register it with autohand mcp add) or a script in your repository that the runbook names. Keep tokens in that server’s or script’s environment, not in the runbook.

Terraform integration

Terraform gives you a declarative, version-controlled model of infrastructure, so remediation that changes infrastructure stays reviewable and auditable.

Benefits

  • Reviewable changes: Autohand writes the change as a patch to your .tf files; your pipeline plans and applies it
  • Drift checks: Autohand can run terraform plan read-only and explain the drift
  • Audit trail: every change is a commit with a reviewer

Plan review workflow

# 1. Autohand prepares the change as a patch
autohand -p "Increase volume_size in infra/storage/ebs.tf to 150 GB, following runbooks/disk-pressure.md." \
  --disallowed-tools run_command,shell --patch --output ebs.patch

# 2. Apply the patch on a branch and let your pipeline run terraform plan
git switch -c inc-1234-ebs && git apply ebs.patch
terraform -chdir=infra plan -out=tfplan

# 3. Ask Autohand to explain the plan for the reviewer
terraform -chdir=infra show -no-color tfplan \
  | autohand -p "Summarize this Terraform plan for a reviewer and flag anything destroyed or replaced." --restricted

Keep terraform apply in your pipeline, behind your approval rules. Add it to permissions.denyList so Autohand cannot run it.

Safeguards

Safeguards stop a runbook run from causing more harm than the original incident:

  • Deny rules: permissions.denyList in the config blocks commands outright, whatever the prompt says.
  • Read-only runs: --restricted denies all dangerous operations automatically. Use it for checks and diagnosis.
  • Preview: --dry-run previews actions without applying them, and --patch produces changes without writing files. Patch mode approves tool calls automatically, so add --disallowed-tools run_command,shell to keep a patch run from executing commands.
  • Tool scope: --allowed-tools and --disallowed-tools limit the tools for one run.
  • Run budgets: --max-duration, --max-requests and --max-tokens stop a run that goes on too long.
  • Isolation: --worktree runs a session in a separate git worktree.

Deny rules go under permissions in ~/.autohand/config.json or the project config. Autohand runs commands through two tools, run_command and shell, and a rule names one tool, so add each rule for both:

{
  "permissions": {
    "denyList": [
      "run_command:kubectl delete:*",
      "shell:kubectl delete:*",
      "run_command:terraform apply:*",
      "shell:terraform apply:*",
      "run_command:terraform destroy:*",
      "shell:terraform destroy:*"
    ]
  }
}

For rules that depend on context, such as a change freeze during business hours, use a pre-tool hook. A hook that exits with code 2 blocks the tool call:

{
  "hooks": {
    "enabled": true,
    "hooks": [
      {
        "event": "pre-tool",
        "matcher": "^(run_command|shell)$",
        "command": "./scripts/change-freeze.sh",
        "description": "Block commands during the change freeze"
      }
    ]
  }
}

The script receives the tool name in HOOK_TOOL and its arguments as JSON in HOOK_ARGS. Hooks do not run with --bare, so rely on permissions.denyList, --restricted and --allowed-tools in bare CI runs.

Human-in-the-loop

Autohand has no built-in approval workflow in Slack or PagerDuty. Human review comes from three places:

  • Approval prompts: in an interactive session, Autohand asks before running a command or changing a file, unless you allow it in the config or with --yes.
  • Patch review: --patch --output writes a patch your team reviews in a pull request, with your usual approvers and branch protection.
  • Structured reports: --output-schema turns a diagnosis into JSON your own bot can post to Slack or attach to the incident for a decision.
cat alert.json \
  | autohand --ephemeral -p "Using runbooks/disk-pressure.md and this alert, recommend the next action." \
      --restricted --output-schema recommendation.schema.json --json local \
  | jq -r .content > recommendation.json

If the answer does not match the schema, the command exits with status 1, so your bot can fall back to paging a person.

Testing runbooks

Replay saved alerts through a runbook before you rely on it in production:

# Check that the runbook's checks make sense for a saved alert, read-only
autohand --ephemeral -p "Using runbooks/disk-pressure.md, list the checks and actions you would take for this alert." \
  --restricted < fixtures/disk-92-percent.json

# Preview every action the runbook would take, without applying it
autohand --ephemeral -p "Follow runbooks/disk-pressure.md for this alert." \
  --dry-run < fixtures/disk-92-percent.json

# Review the runbook itself for gaps and unsafe steps
autohand -p "Review runbooks/disk-pressure.md for missing limits, unsafe commands and missing rollback steps." --restricted

Run runbooks against a staging environment before you point them at production.

Runbook library

Common runbook patterns to get started:

Runbook Trigger Action
Pod restart loop CrashLoopBackOff count > 5 Find the failing change, propose a rollback, notify team
High memory pressure Memory > 90% for 5m Analyze top processes, propose scaling as a patch
Certificate expiry Cert expires in < 7 days Report affected certificates, start the renewal workflow
Database connection pool Available connections < 10% Identify slow queries, propose pool or instance changes
API error rate spike 5xx rate > 1% Correlate with recent deploys, page on-call

Autohand has no runbook templates to install. Ask it to draft a runbook from your incident history and review the draft like any other change:

cat postmortems/2026-*-memory*.md \
  | autohand -p "Write runbooks/high-memory.md for the payment-api in namespace production, using the structure of runbooks/disk-pressure.md and what these postmortems taught us." \
      --disallowed-tools run_command,shell --patch --output high-memory-runbook.patch

Last updated on

Was this helpful?

Send Feedback

Help us improve this documentation page. Your feedback is valuable.

We'll only contact you if we need clarification