Examples

Runnable sample agents: Kubernetes, Terraform, a remediation bot, a CI gate, an LLM agent's tools and signed intents.

Small, commented agents in sdk/examples. The scripts each print what they would run until you pass --apply, and without FLOODWALL_KEY prints the change it would ask about and stops, so you can run them before you have a plane.

ExampleLanguageWhat it shows
deploy-agent.mjsTypeScriptRolls an image out to a few services, one guard() each.
kubernetes-scaler.mjsTypeScriptGuards a kubectl scale; handles NotAdmitted and plane errors.
terraform-apply.pyPythonterraform apply per workspace, blast radius from the workspace's name.
remediation-bot.pyPythonRestarts unhealthy services, one intent each; handles held and rejected.
ci-gate.mjsTypeScript + YAMLA CI step that asks before deploying and fails the job if not admitted.
llm-agent-tool.mjsTypeScriptAn AI agent's tool calls, each through guard().
signed-agent.mjsTypeScriptAn Ed25519 key for the keyring, and signed intents.
mcp-config.jsonJSONRegisters the @floodwall/mcp server with Claude Code or Cursor.
claude-code-settings.jsonJSONClaude Code hooks: risky Bash commands blocked unless admitted.
agent-sdk-agent.mjsTypeScriptA Claude Agent SDK agent with claudeAgentSdkHooks() on its shell commands.
langgraph-agent.pyPythonA LangGraph agent with a guarded_tool and a guard_node.

Running them#

sh
git clone https://github.com/erphq/floodwall && cd floodwall
export FLOODWALL_KEY=fw_live_...     # an agent key from the console
export FLOODWALL_PLANE=pl_...        # the plane's id
# export FLOODWALL_URL=...           # optional: another API base URL
node sdk/examples/kubernetes-scaler.mjs web 5

They import the clients from the checkout, so they need no install: Node 20+ and Python 3.9+. In your own project, npm install @floodwall/client or pip install floodwall and import from the package. To see every verdict, try them against a plane with these rules:

rules
format 1

policy "guardrails" {
  reject "{resource} holds state, so no agent may take it to zero"
    when destructive and resource matches "*-db"
  defer "a region-wide change waits for a person"
    when blast_radius >= region and priority < pager
  defer "scaling {resource} to {replicas} needs a person"
    when replicas > 10
}

Deploy agent#

deploy-agent.mjs rolls an image out to web, api and billing, asking before each and reporting how it went. A service that isn't admitted is skipped with the reason; the rest carry on.

sh
node sdk/examples/deploy-agent.mjs v42

Kubernetes scaler#

kubernetes-scaler.mjs guards a kubectl scale. A scale to zero is destructive, so rules can hold or refuse it. It exits 1 when the change isn't admitted, so it can sit in a script.

js
const change = { action: { kind: "scale", resource: deployment, replicas }, priority: "normal", blastRadius: "service" };

try {
  await fw.guard(change, () => execFileSync("kubectl", ["--namespace", ns, "scale", `deployment/${deployment}`, `--replicas=${replicas}`]),
    { timeoutSeconds: 120 });
} catch (error) {
  if (error instanceof NotAdmitted) {
    console.error(`not admitted (${error.decision.status}: ${error.decision.reason})`);
    process.exit(1);
  }
  throw error;
}
sh
node sdk/examples/kubernetes-scaler.mjs web 5 --namespace prod --apply

Terraform apply per workspace#

terraform-apply.py makes each workspace one intent, an apply of the revision to terraform/<workspace>, with a blast radius read from the name: dev is a cell, staging a service, prod-* a region, anything global global. A held prod-eu waits up to 15 minutes for someone to release it, while dev goes straight through.

python
def blast_radius(workspace: str) -> str:
    if "global" in workspace:
        return "global"
    if workspace.startswith("prod"):
        return "region"
    if workspace.startswith("staging"):
        return "service"
    return "cell"

fw.guard(
    {"action": {"kind": "apply", "resource": f"terraform/{workspace}", "manifest": revision},
     "priority": "urgent" if radius in ("region", "global") else "normal",
     "blast_radius": radius},
    apply,                      # terraform workspace select + terraform apply
    timeout_seconds=900,
)
sh
python3 sdk/examples/terraform-apply.py dev staging prod-eu --chdir infra --revision $(git rev-parse HEAD)

Remediation bot#

remediation-bot.py checks each service's health and asks to restart the unhealthy ones, one intent each: urgent when a service is down, normal when it is degraded. It waits a minute at most: a held restart is left for a person, and a rejected one is left alone.

python
try:
    fw.guard(restart_change(service, health), restart, timeout_seconds=60)
except NotAdmitted as error:
    if error.decision["status"] == "held":
        print(f"{service}: held for a person; not restarting now")
    else:
        print(f"{service}: {error.decision['status']}; leaving it alone")

A held restart that someone releases after the bot has moved on is admitted with nobody to apply it. Give the plane a fail lease so it lapses instead of holding the service.

CI gate (GitHub Actions)#

ci-gate.mjs has two commands. ask submits the deploy, waits while it is queued or held, and exits 0 if it is admitted (writing intent_id to $GITHUB_OUTPUT) or 1 if not, failing the job. report tells the plane how the deploy went. Without its secret, ask fails, so a job never deploys unasked. github-actions-deploy.yml wires it up:

github-actions-deploy.yml
      - name: Ask Floodwall
        id: gate
        run: node sdk/examples/ci-gate.mjs ask --resource api --manifest "${{ github.sha }}" --timeout 600

      - name: Deploy
        id: deploy
        run: ./deploy.sh

      - name: Report to Floodwall
        if: always() && steps.gate.outputs.intent_id != ''
        run: >
          node sdk/examples/ci-gate.mjs report
          --id "${{ steps.gate.outputs.intent_id }}"
          --outcome "${{ steps.deploy.outcome == 'success' && 'succeeded' || 'failed' }}"

Add FLOODWALL_KEY (an agent key bound to github-actions) and FLOODWALL_PLANE as repository secrets. When a deploy is held, release it in the console or Slack and re-run the job.

LLM agent tools#

llm-agent-tool.mjs governs an AI agent's tools without tying itself to a model provider. Each tool declares how a call becomes a change; one wrapper asks the plane, runs the tool only if admitted, and always hands the model a sentence, so a refusal is something the model reads and works around, not an exception that ends the conversation.

js
async function handleToolCall({ name, arguments: args }) {
  const tool = TOOLS[name];
  try {
    const output = await fw.guard(tool.change(args), () => tool.run(args), { timeoutSeconds: 30 });
    return `done: ${output}`;
  } catch (error) {
    if (error instanceof NotAdmitted) {
      if (error.decision.status === "held") return "not run yet: held for a person to approve. Don't retry it.";
      return `refused: ${error.decision.reason}. Don't retry the same change.`;
    }
    return `failed: ${error.message}`;
  }
}

Give the model its own agent name and a key bound to it, so its changes are rate-limited, ruled on and recorded apart from everyone else's.

Agents built on LLMs#

Four ways to put the wall where a model acts, each with an agent key and its own agent name. Each asks before the change, stops unless the answer is admit, reports the outcome, and refuses the change when the plane cannot be asked.

mcp-config.json registers the MCP server (submit_intent, wait_verdict, report_outcome, list_held) with Claude Code as .mcp.json or with Cursor as .cursor/mcp.json. Or from the command line:

sh
claude mcp add floodwall -e FLOODWALL_API_KEY=fw_live_... -e FLOODWALL_PLANE=pl_... -- npx -y @floodwall/mcp@0.1.0

claude-code-settings.json holds Claude Code hooks for .claude/settings.json: PreToolUse on Bash submits kubectl, terraform apply|destroy and helm commands and blocks them unless the plane admits them; PostToolUse reports how they went. These run whether or not the model chooses to ask.

agent-sdk-agent.mjs is a Claude Agent SDK agent whose shell commands go through claudeAgentSdkHooks() from @floodwall/mcp/agent-sdk (npm install @floodwall/mcp@0.1.0); a refusal reaches the model as a denied tool call with the plane's reason.

langgraph-agent.py is a LangGraph agent (pip install floodwall[langgraph]) with a guarded_tool and a guard_node.

Signed agent#

signed-agent.mjs makes an Ed25519 key with WebCrypto, prints the seed to keep secret and the public key for the plane's keyring, signs an intent and checks the signature as the plane would. With AGENT_SEED_HEX and --submit it submits through the client, which signs every intent.

sh
node sdk/examples/signed-agent.mjs
# AGENT_SEED_HEX=9a40…            keep secret
# {"keyring":{"agents":{"signed-agent":"2d47…"}}}   for the plane's keyring
AGENT_SEED_HEX=9a40… node sdk/examples/signed-agent.mjs --submit