command-policy
The built-in Policy command-policy, against dangerous command lines: production kubectl, the wrong package manager, a subagent that should only read: its defaults, its options and a configuration that writes it.
To learn what it guards against and see it at work, read the guide: Commands.
Defaults
| Default | Value |
|---|---|
| On by default | no: an entry turns it on |
| Fail mode | closed |
| Timeout | 10000 ms |
| Events | PreToolUse |
| Tools | Bash |
| Agent types | every agent, or as its options set |
Options
| Option | Type | Default | Description |
|---|---|---|---|
agentTypes | string[] | — | The agent types the Policy runs for, such as verifier; every agent and the main session when absent. |
aliases | string[] | — | Other names of the tool, such as k. |
allow | string[] | object | — | The commands allowed, each a prefix of the command's words (rollout status, * for every command), inline or { file } with one item per line. |
alwaysDenyTokens | object[] | — | Words refused before anything else, among the tool's arguments or, with anywhere, in any word of any command. |
context | object | — | Where the context comes from: a flag (context.flag) or a command (context.command). |
default | "allow" | "ask" | "deny" | — | What a command on no list gets: allow (the default), ask or deny. |
deny | string[] | object | — | The commands refused, as allow writes them. |
denyArgs | string[] | — | Patterns an argument must match whole to be refused before anything else, such as db:drop. |
denyAssignments | boolean | — | Refuses a line that sets a variable for what it runs (PATH=… npm …, env NAME=…, env -i, export), so no allowed command runs another program through PATH or NODE_OPTIONS. |
denyBare | boolean | — | Refuses the tool run without words (a bare yarn, which installs), with the deny list. |
denyWrites | boolean | — | Refuses a line that writes a file (a redirection, tee, an in-place edit, a copy, a move or a removal), /dev/null aside. |
exemptWhen | object | — | When a refused command is let through: outsideRepository, when it surely runs in another repository. |
globalValueFlags | string[] | — | The options that take the next word as their value, such as -n; every other word that starts with - is an option on its own. |
launchers | string[] | — | Word sequences that run the tool, such as bundle exec. |
local | string[] | object | — | Commands allowed without the context being looked up, as allow writes them. |
message | string | — | The fix the agent reads with every refusal, in place of the table's own. |
production | string[] | object | — | Patterns of production contexts, in which everything is refused. |
subcommandAliases | object | — | A first word that stands for others, such as kl for k8s logs. |
subcommandPrefix | string[] | — | Words a command of the tool must start with to be screened, such as k8s; they are not part of its words. |
tool | string | — | The program the table screens, by the last part of its path, such as kubectl; without it the table screens every command. |
packageManager | "bun" | "npm" | "pnpm" | "yarn" | — | With the preset package-manager, the repository's own package manager, whose commands are not refused; detected when absent. |
preset | "argocd" | "bun" | "django-db" | "helm" | "kubectl" | "npm" | "package-manager" | "pnpm" | "prisma-db" | "rails-db" | "yarn" | — | A command table of the kit, whose fields the ones written beside it replace, such as kubectl or package-manager. |
Example
A configuration that writes every option, a comment above each:
import { defineConfig } from '@microeinhundert/harness-kit';
export default defineConfig({
// The Policy entries, in the order their Decisions merge in.
policies: [
{
// The Policy's name, unique in the configuration; messages and logs name the Policy by it.
id: 'command-policy',
// The constructor's options, which it decodes.
options: {
// The agent types the Policy runs for, such as `verifier`; every agent and the main session
// when absent.
agentTypes: ['verifier'],
// Other names of the tool, such as `k`.
aliases: ['k'],
// The commands allowed, each a prefix of the command's words (`rollout status`, `*` for
// every command), inline or `{ file }` with one item per line.
allow: ['rollout status'],
// Words refused before anything else, among the tool's arguments or, with `anywhere`, in
// any word of any command.
alwaysDenyTokens: [
{
// Whether the word is refused in any word of any command the line runs, not only among
// the tool's arguments.
anywhere: true,
// The word that is refused wherever it stands.
token: 'argocd',
},
],
// Where the context comes from: a flag (`context.flag`) or a command (`context.command`).
context: {
// The command that prints the context, its program and arguments, run once per command
// line when the flag is absent; a failed or empty answer leaves the context unknown.
command: ['kubectl'],
// The option that names the context on the command line, such as `--context`, also as
// `--context=<name>`; it is read anywhere in the command.
flag: '--context',
// Options of the screened command copied into the command that prints the context, after
// its program.
passFlags: ['--kubeconfig'],
// The context an unknown one counts as, matched against the production patterns; without
// it an unknown context counts as production.
unknown: 'staging',
},
// What a command on no list gets: `allow` (the default), `ask` or `deny`.
default: 'allow',
// The commands refused, as `allow` writes them.
deny: ['rollout status'],
// Patterns an argument must match whole to be refused before anything else, such as
// `db:drop`.
denyArgs: ['db:drop'],
// Refuses a line that sets a variable for what it runs (`PATH=… npm …`, `env NAME=…`,
// `env -i`, `export`), so no allowed command runs another program through `PATH` or
// `NODE_OPTIONS`.
denyAssignments: true,
// Refuses the tool run without words (a bare `yarn`, which installs), with the deny list.
denyBare: true,
// Refuses a line that writes a file (a redirection, `tee`, an in-place edit, a copy, a move
// or a removal), `/dev/null` aside.
denyWrites: true,
// When a refused command is let through: `outsideRepository`, when it surely runs in
// another repository.
exemptWhen: {
// Exempts a command that surely runs in another git repository than the session's,
// through a chain of plain `cd`s joined by `;` or `&&` before it, or through one of the
// `folderFlags`; a command whose folder is in doubt is not exempt.
outsideRepository: {
// Options that name the folder a command runs in, such as `--prefix <folder>`.
folderFlags: ['--prefix'],
},
},
// The options that take the next word as their value, such as `-n`; every other word that
// starts with `-` is an option on its own.
globalValueFlags: ['-n'],
// Word sequences that run the tool, such as `bundle exec`.
launchers: ['bundle exec'],
// Commands allowed without the context being looked up, as `allow` writes them.
local: ['rollout status'],
// The fix the agent reads with every refusal, in place of the table's own.
message: 'Ask the user to run it against production.',
// Patterns of production contexts, in which everything is refused.
production: ['prod'],
// A first word that stands for others, such as `kl` for `k8s logs`.
subcommandAliases: {
kl: 'k8s logs',
},
// Words a command of the tool must start with to be screened, such as `k8s`; they are not
// part of its words.
subcommandPrefix: ['k8s'],
// The program the table screens, by the last part of its path, such as `kubectl`; without
// it the table screens every command.
tool: 'kubectl',
// With the preset `package-manager`, the repository's own package manager, whose commands
// are not refused; detected when absent.
packageManager: 'bun',
// A command table of the kit, whose fields the ones written beside it replace, such as
// `kubectl` or `package-manager`.
preset: 'argocd',
},
// The name of the kit's Policy constructor that builds the Policy.
use: 'command-policy',
},
],
});hook-bypass
The built-in Policy hook-bypass, against the agent switching its own guardrails off: its defaults, its options and a configuration that writes it.
branch-name
The built-in Policy branch-name, against commits and pushes to shared branches, lost stashes, merges only people should make: its defaults, its options and a configuration that writes it.