Destructive Operation Guard Wrapper Prompt
Build a safety wrapper around destructive commands (rm, drop, terraform destroy) with dry-run by default, typed confirmation, scope guards, and an audit trail so a stray script can't nuke prod.
- Target user
- SREs and platform engineers hardening automation that deletes things
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior reliability engineer who has cleaned up after exactly one `rm -rf "$VAR/"` where `$VAR` was empty. Never again.
I will provide:
- The destructive operation(s) to wrap (file deletion, table drop, resource teardown)
- The blast radius (single dir, a namespace, a whole account)
- Who runs it (human, CI, cron) and in what environments
Your job:
1. **Dry-run by default** — the wrapper must default to NOT executing. Real execution requires an explicit `--apply` (or `--force`) flag. In dry-run, print exactly what WOULD be deleted, counted and sized, with no side effects.
2. **Empty/unset guards** — before any deletion, assert target variables are non-empty and not `/`, `~`, `$HOME`, or `.`. Use `set -u`, and add `[[ -n "${TARGET:?TARGET is required}" ]]`. Reject globs that expand to zero matches. Reject paths above an allowed root via realpath prefix check.
3. **Typed confirmation** — for interactive runs, require the user to type a non-trivial token (the resource name or `DELETE 42 files`), not just `y`. Skip the prompt only when `--apply --yes` AND a non-TTY CI context is detected; document that combination as the only unattended path.
4. **Scope + environment guards** — refuse to run against prod unless `ALLOW_PROD=1` is exported AND the resource label matches an allowlist. Add a `--limit N` cap that aborts if the operation would affect more than N items.
5. **Soft-delete / recoverable mode** — prefer move-to-trash, snapshot, or rename-with-tombstone over hard delete when feasible; offer a `--hard` opt-out. Print the exact restore command.
6. **Audit trail** — log who/what/when/where to a file and (optionally) syslog: timestamp, user, host, command, item count, dry-run vs apply. Make the log append-only-friendly.
7. **Idempotency + exit codes** — re-running after a partial failure must be safe. Return 0 only when the desired end-state is reached; distinct non-zero codes for guard-tripped vs partial-failure.
Output: (a) the complete wrapper function/script, (b) a table of every guard and what triggers it, (c) 3 abuse cases it defends against with the exact failure message, (d) a one-line install snippet to alias the raw command behind the guard.
Bias toward: defaulting to safe, loud refusals over silent destruction, and recoverability everywhere.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Bash Dry-Run Mode Pattern Prompt
Add a first-class `--dry-run` mode to a Bash automation script so every mutating action is previewed instead of executed — with a single `run()` wrapper, clear PLAN output, and no accidental side effects.
-
Bash Safe In-Place sed Edit Wrapper Prompt
Build a Bash wrapper around sed -i that backs up, validates, and atomically applies in-place edits so a bad expression can never corrupt or truncate config files
-
Bash Script Safety & Portability Review Prompt
Audit an existing Bash script line by line for unsafe quoting, missing strict mode, destructive commands, race conditions, and bashisms that break portability, and return prioritized fixes.
-
Trap-Driven Cleanup & Rollback Bash Script Prompt
Write a robust Bash script that uses set -euo pipefail plus EXIT/ERR/INT traps to guarantee temp-file cleanup and partial-work rollback even when a command fails midway.
More Bash & Python Automation prompts & error guides
Browse every Bash & Python Automation prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.