Stop GitHub Copilot (CLI and VS Code agent mode) from running terraform destroy, kubectl delete or DROP TABLE
Copilot CLI and Copilot agent mode in VS Code can run terminal commands on their own once you’ve approved a tool or a session. Both support a preToolUse hook that runs before each terminal command and can deny it with a reason.
Aegis-DevOps is that hook. It checks each command against your policy before it runs and blocks what the policy forbids, with the reason shown to the model. It’s open source (Apache-2.0) and decides in under a millisecond.
Install
pip install aegis-devops
aegis init .aegis # opt this project in
copilot plugin install moneytool/aegis-devops:plugins/copilot
Or as a hook: aegis install copilot --user (Copilot CLI, every project) or aegis install vscode (VS Code, this workspace). VS Code runs hooks only in trusted workspaces.
What happens
Ask the agent to run terraform destroy, kubectl delete namespace prod or psql -c 'DROP TABLE users' in the project. Copilot refuses the command and shows the reason:
aegis: BLOCK: block-namespace-delete, no-delete-in-prod-namespace, plan-k8s-delete-ratio
kubectl get pods and other commands the policy has no rule against run as normal. An ESCALATE verdict becomes Copilot’s “ask”, so you approve or refuse it yourself.
What the example policy blocks
aegis init writes an example policy. Besides its demo rules it blocks terraform destroy / tofu destroy, pulumi destroy, deleting a Kubernetes namespace or node, an S3 bucket, an RDS database, a GCP project or an Azure resource group, dropping a database or deleting every row of a table, force-pushing main, deleting Helm releases in production, and kubectl --as impersonation. Deleting an Argo CD application asks first.
Everything else runs as usual: kubectl get pods, terraform plan, ls, npm test. Aegis only acts in projects that opted in (a .aegis/ directory in the project or a parent, $AEGIS_CONFIG_DIR, or ~/.config/aegis), so installing the hook changes nothing in your other projects.
Check a command without the agent
$ aegis check command --pretty -- "terraform destroy -auto-approve"
BLOCK: terraform delete workspace/current
citations: block-terraform-destroy
covered: True latency_ms: 0.1449
PLAN BLOCK: 1 intent(s)
STORE: loaded=30 quarantined=0 principals=3
warning: using example signing key
$ aegis check command --pretty -- "kubectl get pods -n prod"
ALLOW: kubernetes get pod/*
covered: False latency_ms: 0.0086
PLAN ALLOW: 1 intent(s)
STORE: loaded=30 quarantined=0 principals=3
warning: using example signing key
Aegis reads the command the way the tool would: kubectl -n prod delete ns app, sudo kubectl ... and cd infra && terraform destroy all resolve to the same action as the plain form.
Write your own rule
Rules live in .aegis/constraints*.yaml. This is the rule behind the terraform destroy block:
- id: block-terraform-destroy
provider: terraform
resource_pattern: workspace/*
actions: [delete]
effect: BLOCK
constraint_class: deletion
principal: admin
rule_text: Block 'terraform destroy' and 'tofu destroy' (and apply -destroy)
effect is BLOCK or ESCALATE; a command no rule matches is allowed. See writing constraints for the resource names each tool produces, scopes such as namespace, region and environment, and time windows.
Why the rules are signed
The agent reads tickets, pull request comments and docs, and any of them can contain text that looks like an instruction or a rule. Aegis only counts a rule if nobody has edited it since it was signed, and if its author is allowed to write that kind of rule (the authority map in authority.yaml). A rule that fails either check is discarded and reported, so a line planted in a ticket can’t become policy, and can’t be used to stall the agent either.
Before you rely on the policy, replace the example signing key with your own: aegis keygen, then aegis sign. See configuration.
Details
Hook used: preToolUse (Copilot CLI) and PreToolUse on run_in_terminal (VS Code). Full notes on every agent, including what happens when the policy itself is broken: coding agents.
Also for: Claude Code, Cursor, Codex CLI, Gemini CLI, and Terraform plans in CI.