Commands
command-policy screens every shell command line against a command table, from ready-made presets for kubectl and package managers to an allow-list for one subagent.
Stop the agent from running commands it should never run: deleting pods, deploying with Helm, dropping a database, installing with the wrong package manager. command-policy screens every Bash command line against a command table and answers deny, ask or allow.
It reads the line the way the shell does: a command behind sudo, sh -c, a pipe into a shell or a heredoc is screened, one merely quoted in text is not.
API reference
command-policy.Screen commands with command-policy
Add one entry per command table. This configuration refuses production kubectl, the wrong package manager and, for one subagent, everything its allow-list does not name:
import { defineConfig } from '@microeinhundert/harness-kit';
/**
* Three command tables: kubectl kept read-only with every context named `prod-…` refused outright, the package
* managers the repository does not use refused, and a `reviewer` subagent allowed only to read.
*/
export default defineConfig({
policies: [
{
id: 'kubectl',
options: {
preset: 'kubectl',
production: ['^prod-'],
},
use: 'command-policy',
},
{
id: 'package-managers',
options: {
preset: 'package-manager',
},
use: 'command-policy',
},
{
id: 'reviewer-commands',
options: {
agentTypes: ['reviewer'],
allow: ['git status', 'git diff', 'git log', 'npm test'],
default: 'deny',
denyAssignments: true,
denyWrites: true,
message: 'The reviewer only reads: git status, git diff, git log and npm test.',
},
use: 'command-policy',
},
],
});The third entry is an allow-list for one subagent: a table without tool screens every command, default: 'deny' refuses what the list does not name, and denyWrites with denyAssignments keeps the allowed commands from writing files or swapping programs.
A table that cannot decide refuses.
Start a table from a preset
Most tables start from a preset. A field you write beside preset replaces the preset's.
| Preset | What it does |
|---|---|
kubectl | allows reading verbs, refuses writes, exec and unknown verbs; refuses everything in a context matching prod; refuses apply anywhere |
helm, argocd | refused wherever they run or are named |
rails-db, prisma-db, django-db | refuse the tasks that drop or reload a database |
npm, pnpm, yarn, bun | refuse the commands that change what is installed (a bare yarn included), except in another repository |
package-manager | the tables of every manager except the project's own, telling the agent which one the repository uses |
The presets reference shows each table in full.
What the agent reads
Each refusal names the command, the rule that matched and a fix.
`kubectl --context prod-eu get pods` is refused: context `prod-eu` is a production context, where the kubectl command table allows only local commands.
Fix: Do not run it; if it is needed, ask the developer to run it by hand.`yarn add left-pad` is refused: `add` is on the deny list of the yarn command table.
Fix: This repository uses npm: run the command with npm instead.`npm publish` is on no list of the command table.
Fix: The reviewer only reads: git status, git diff, git log and npm test.A line the parser cannot read completely is screened on what it recovered and on its raw text, and the refusal says so. The raw text is the text the line runs as code: the body of a heredoc that feeds no interpreter (cat <<'EOF') is not read as commands.
Turn it off
Remove the entry.
To let a person run refused commands for a session, give the entry an override. Its environment variable loosens the whole table. The lines of its allow file that start with the tool (kubectl rollout restart) become allow items of the table. The override never unblocks the deny list, a production context or a refused token.
Related
- Protection: files are guarded separately from commands.
- Recipes: kubectl and subagent walkthroughs.
Protection
self-protection and hook-bypass keep the agent from switching its own guardrails off. Both run in every configuration.
Git and forge
Eight Policies that read the git and forge commands a Bash call would run, and refuse commits and pushes to shared branches, lost stashes, merges only people should make.