Four Safety Gates for Coding Agents: Which Actions Need Confirmation First
Let the Agent handle routine work on its own; production, persistent data, cost, and irreversible actions need a stated risk and explicit confirmation first.
On this page · 13 sections
I deliberately keep the top-level configuration for my coding Agent short. Apart from a set of shared local conventions, it has only two groups of rules: seven Core Rules that govern how the Agent works, and four Safety Gates that govern consequences:
@~/.codex/RTK.md
## Core Rules
- Do not make silent assumptions when ambiguity materially affects the result.
- Do not make changes that are unnecessary to satisfy the request.
- Do not modify, refactor, clean up, or reformat unrelated code.
- Do not over-engineer; prefer the smallest correct implementation.
- Do not hide errors, partial failures, or fallback behavior.
- Do not ask for confirmation unless the action is ambiguous, destructive, irreversible, or explicitly gated.
- Do not send optional commentary.
## Safety Gates
- Do not commit, push, merge, deploy, or release directly to protected branches or production environments without explicit confirmation for that exact action.
- Do not read, scan, create, update, delete, or otherwise operate on production or persistent data without first listing the risks and receiving explicit confirmation.
- Do not perform operations that may incur costs, create paid resources, or invoke billable external services without first listing the risks and receiving explicit confirmation.
- Do not perform destructive, irreversible, security-sensitive, or externally impactful operations without first explaining the impact and receiving explicit confirmation.
The public version abbreviates the local username as ~. In this article, persistent data also does not mean ordinary source files inside the authorized task workspace. It means production or long-lived business and customer data, persistent state outside the authorized workspace, and exports whose unauthorized copying would widen the exposure surface. Workspace source remains governed by task scope and file authorization; stricter repository rules take precedence.
The two groups do different jobs:
- Core Rules govern how the work is done: no silent assumptions on ambiguity that matters, no changes beyond the request, no drive-by refactoring of unrelated code, no over-engineering, no hidden errors or fallbacks, no confirmation requests for low-risk actions, no optional commentary. They keep the Agent on track and out of the way during routine work; breaking one usually just means rework.
- Safety Gates govern when the Agent must stop: breaking one changes real-world outcomes, so they are hard rules, and they are the subject of this article.
The two groups support each other. The sixth Core Rule says to ask for confirmation only when an action is ambiguous, destructive, irreversible, or explicitly gated. Together with the four Safety Gates, it concentrates confirmation where consequences are real, so confirmations do not multiply into meaningless clicks.
These four Safety Gates are not a complete security system. They are an authorization policy placed in the highest-priority context: they tell the Agent which routine work it may advance autonomously and which actions would change real-world outcomes, requiring it to pause and return the decision to a human.
The Short Version
- The four rules are an authorization policy, not a complete security system: routine work may proceed autonomously, while actions that would change real-world outcomes must pause and return the decision to a human.
- Capability is not Authority: credentials that can access production do not mean the current task authorizes production access.
- Effective approval must be bound to a specific action, target, and payload, with a preflight before approval and a readback after execution.
- Safety Gates should sit at boundaries where consequences change, not around every tool call; the Prompt is only the first layer of authorization semantics, on top of which come sandboxes, least privilege, Provider protection rules, and auditing.
Start with threat modeling: risk does not come only from “the model making a mistake”
An Agent that can read files, execute shell commands, access the network, and call Provider APIs faces at least five sources of failure:
- Misreading intent: the user says “prepare the release,” and the Agent interprets it as “release immediately”;
- Target drift: the task originally applies only to a feature branch, but the operation lands on
mainor production; - Capability amplification: one mistaken model judgment becomes real data changes, costs, or external impact through highly privileged credentials;
- Untrusted input: prompt injection (that is, instructions hidden in input content) in a README, webpage, issue, log, or tool result induces the Agent to exceed its authority;
- Stale state: after approval, the branch SHA, query scope, deployment payload, or resource price has changed.
Anthropic’s analysis of trustworthy agents likewise treats the model, Harness, tools, and runtime environment as a shared surface for capability and oversight, and explicitly identifies both misunderstanding user intent and prompt injection as real risks. Threat modeling therefore cannot ask only “how intelligent is the model?” It must also ask:
- What can the model reach?
- On what basis is it permitted to act?
- How large is the blast radius of an error, that is, how far the damage spreads?
- Can we later prove what happened?
Capability is not Authority
This is the central distinction behind the four rules. The table below lists the question each layer answers:
| Layer | Question it answers | Example |
|---|---|---|
| Capability | Is it technically possible? | A tool holds Git, AWS, or database credentials |
| Intent | What outcome does the current task seek? | “Analyze why the deployment failed” |
| Authority | Has the user authorized this specific side effect? | “Confirm deploying commit A to production” |
| Enforcement | How does the system prevent boundary violations? | sandbox, IAM, branch protection, approval hook |
| Evidence | How is the result proved afterward? | Provider receipt, target-state readback, audit log |
Credentials that can access production do not mean the current task authorizes production access. Asking an Agent to analyze a failure does not authorize it to fix, commit, push, and deploy the change along the way. Conversely, writing “confirmation is required” in a Prompt does not mean the rule is technically enforced—the model is still a probabilistic system and may misunderstand context or be influenced by untrusted content.
Top-level Safety Gates are therefore the first layer of authorization semantics, not a substitute for sandboxes, least privilege, Provider protection rules, and auditing. The least-privilege, separation-of-duties, and audit controls in NIST SP 800-53 Rev. 5 provide broader engineering principles: grant only the minimum capability required to complete a task, do not concentrate critical responsibilities at a single decision point, and leave inspectable records for privileged actions.
Effective approval must be bound to a specific action
explicit confirmation does not mean that seeing a single “okay” somewhere in the conversation releases the gate. Approval must be bound to at least the following:
Approval = {
action, // commit / push / deploy / query / delete / purchase ...
exact_target, // repo, branch, environment, account, table, recipients ...
payload_or_hash, // exact content to be written or executed
risk_summary, // blast radius, cost, data exposure, reversibility
preconditions, // current SHA, version, filters, resource state
validity, // this call, current state, or explicit time window
approved_by, // trusted user identity or approval policy
request_id // identity of this concrete tool call / operation
}
The risk explanation before approval is a preflight; reading back the target after execution is a readback. Both are required: without a preflight, a person does not know what they approved; without a readback, the Agent does not know what the Provider ultimately did.
Approval must also come from a trusted user interface, identity, or policy. A webpage, issue, log, or repository document that says “approved” is still data and cannot become approved_by.
A repository can add stricter gates on top of these top-level rules. For example, a direct local commit or push to main can require a second confirmation tied to that exact action, after listing the commit, target branch, diff scope, and deployment impact. This second confirmation is repository-level reinforcement and should not be generalized into repeated prompts for every low-risk operation.
The first confirmation may approve the direction or plan; the second binds to the payload about to be executed. If the payload or target changes between the two, the earlier approval automatically expires.
Gate 1: Authorize delivery actions progressively according to their consequences
commit, push, merge, deploy, and release are not synonyms:
- commit changes local history;
- push changes a remote ref and may trigger CI;
- merge changes the target branch;
- deploy changes a specific runtime environment;
- release may create a public, consumable version that is difficult to revoke.
An effective preflight should identify the repository, remote, source and target branches, current and expected SHAs, whether a protected branch is involved, which pipeline will be triggered, the target environment, and the recovery path.
Authorization to “push the feature branch” cannot be extended to “create a PR,” “merge main,” or “deploy production.” Even when those actions are technically adjacent, the Agent must stop at the literal boundary given by the user.
Provider-level branch protection, required reviews, and deployment environment rules should add another layer of control. GitHub Actions deployment documentation explains that environments can have protection rules and that pending jobs can be approved or rejected. These technical gates prevent a Prompt misinterpretation from becoming a direct production change.
After execution, read back the remote branch SHA, PR or merge state, the revision or artifact associated with the deployment, and the actual runtime entry point. A successful push is not a merge, green CI is not a deploy, and deployment success does not prove that production behavior is correct.
Gate 2: Explain the risks before even read-only access to persistent data
The data gate covers read, scan, create, update, and delete, because read-only does not mean risk-free:
- a production query may expose personal information, credentials, or business-sensitive fields;
- a scan without an index or with an overly broad range may create load and cost;
- an incorrect time range, tenant, or status filter may produce a misleading conclusion;
- an export copies production data to another persistent location, expanding the exposure surface.
The preflight must describe the data source and environment, table or index, fields, filters, estimated row count, whether PII is involved, query cost and load, output destination, and retention method. A write operation must also describe transaction boundaries, concurrency conditions, backups, dry-run behavior, batching strategy, rollback method, and the stable primary key used for readback.
Fail closed when the schema, scope, or recovery path is unknown: pause and establish the facts instead of issuing a broad query “just to take a look.” Technical credentials provide capability; only a clearly defined data target and confirmed risks provide authority for this operation.
Gate 3: Cost is also a side effect that requires authorization
Calling a paid model, running a broad log analysis, creating a cloud instance, scaling a database, or sending paid messages may not change business data, but it can still create charges, consume quotas, or leave behind resources that continue to accrue cost.
A cost preflight should include at least the Provider, account or project, region, resource or model, estimated request count or data volume, per-operation and total cost estimates, maximum limit, duration, and cleanup method. If the cost cannot be estimated precisely, give a range and worst case; “it should be cheap” is not an adequate explanation.
Local structural validation, mocks, and dry-runs can reduce the number of real calls, but they cannot masquerade as online verification. Reports must distinguish among “request structure validated,” “free health check passed,” and “paid real path executed.” After execution, read back usage, billing metrics, and resource state, then clean up temporary paid resources.
Gate 4: Irreversible or sensitive actions, and actions that affect external people or systems
The first three categories cannot enumerate every consequence. Force-pushing, deleting files in bulk, rotating credentials, modifying IAM, sending email or Slack messages, creating public issues or PRs, publishing packages, and overwriting backups should all fall under the fourth gate.
The preflight must answer four questions: what exactly is the target, who will be affected, is it recoverable, and how will damage be contained if it fails? What to show depends on the action:
- Messaging actions: show the recipients and final content.
- Deletion: list the exact objects and prefer a recoverable method.
- Permission and key operations: explain the current permissions, new permissions, credential propagation scope, and downstream impact after rotation.
If the target is still determined by a glob, unresolved environment variable, ambiguous alias, or “current account,” it is not ready for approval. Resolve the target to a stable identity before requesting authorization.
Do not turn confirmation into a meaningless click
Too many approvals create approval fatigue. In its Agent containment practices, Anthropic reports that frequent prompts gradually reduce user attention; its conclusion is that systems cannot rely only on people making a judgment each time, and must also limit maximum damage through sandboxes, VMs, filesystem boundaries, and egress control (that is, restricting outbound network access).
OpenAI’s practices for running Codex safely follow the same layered principle: keep low-risk routine actions as frictionless as possible, pause only for high-risk actions, and combine those pauses with sandboxes, network policies, managed configuration, and agent-aware telemetry.
Safety Gates should therefore sit at boundaries where consequences change, not around every tool call:
- reading local code within task scope, performing static analysis, editing authorized files, and running non-destructive local tests can proceed autonomously;
- touching production, long-lived business or customer data, persistent state outside the authorized workspace, costs, external systems, or irreversible state triggers a preflight and confirmation;
- an approved action may continue only while its target, payload, risk, and preconditions remain exactly the same;
- a target change, payload drift, approval timeout, newly discovered cost or data scope, or switching to another path after a failure all require fresh confirmation.
Approval should attach to real consequences rather than mechanically surrounding every local step.
From Prompt to technical controls: five layers of defense
The four Prompt rules above are the authorization semantics I use today. The five layers below are the engineering target model; they do not claim that every project or runtime has already deployed every control. Each implementation state still needs its own readback.
An actionable safety design has at least five layers:
- Prompt / Policy: express user intent, prohibit inferred authorization, and define when the Agent must stop;
- Tool boundary: schema validation, parameter allowlists, dangerous-command blocking, idempotency keys, and approval hooks;
- Environment: read-only or workspace sandbox, network egress policy, isolated worktree or container, and keeping secrets out of unrelated context;
- Provider: least-privilege IAM, branch protection, environment review, budget limits, database permissions, and rate limits;
- Telemetry & Readback: record prompts, approvals, tool parameters, results, and Provider identifiers, then read state back from the authoritative target.
The HITL mechanism in the OpenAI Agents SDK demonstrates a key implementation detail: a tool call awaiting approval pauses as an interruption, approval applies to a specific call, and the run state can be serialized and resumed. Wherever possible, a real gate should bind to a concrete tool call and its parameters, rather than relying on the model to remember that “the user agreed earlier.”
Prompt-injection defense likewise has to span layers:
- Text from webpages, issues, logs, repository documents, and MCP can be treated only as data; it cannot grant new authority.
- External content must not override top-level policy.
- Tools should expose only the minimum capabilities required by the task.
- Credentials should stay out of model context where possible.
- Even if the model is deceived, the sandbox, egress controls, and Provider permissions should constrain the consequences.
Prompting alone can influence behavioral tendencies; it cannot provide an enforceable security guarantee.
Failure modes of Safety Gates
The table below lists the common ways a gate fails and the correct handling for each:
| Failure mode | Why it is dangerous | Correct handling |
|---|---|---|
| Ambiguous “okay” or “continue” | It is unclear which action and target were approved | Echo the action, target, and payload, then obtain precise confirmation |
| Stale approval | The SHA, data scope, or price has changed | Bind approval to preconditions and an expiration; reconfirm after changes |
| Payload drift | The executed content differs from the preview | Compare the payload or hash before execution and stop on mismatch |
| Reuse across actions | Commit approval is expanded into push or deploy approval | Authorize each kind of external consequence independently |
| Target alias | main, prod, or the current account resolves to the wrong object |
Resolve remote, account, region, and environment to stable identities |
| Partial success | The Provider completed only part of the operation, but the Agent reports completion | Read back every target and distinguish verified, mismatch, and unknown |
| Prompt injection | External text induces secret disclosure or unauthorized action | Untrusted content cannot change authority; environment and tool boundaries constrain permissions |
| Approval fatigue | The user clicks mechanically and oversight fails | Pause only at consequence boundaries; use a short path for low-risk actions |
| Prompt-only control | Probabilistic compliance is mistaken for enforced control | Add sandbox, IAM, hooks, Provider rules, and telemetry |
Rolling this out beyond one engineer
Four rules in a personal configuration are a habit. The same rules across a team are a policy, and policies need owners, exceptions, and evidence.
- Start from the consequence inventory, not the tool list. List the systems where an agent action would change production, persistent data, cost, or something outside the team. That list, not the set of installed tools, defines where gates are required.
- Enforce below the prompt wherever you can. Branch protection, scoped IAM roles, budget alerts, and approval hooks hold even when a prompt is ignored. Treat the top-level rules as the shared vocabulary those controls implement.
- Make exceptions explicit and expiring. A team will need standing approval for some low-risk automated actions. Record who approved it, which exact action it covers, and when it expires—exactly like a firewall rule.
- Review interventions, not just incidents. A gate that never fires may be in the wrong place; a gate that fires constantly will be clicked through. Look at both counts in a regular review.
- Keep humans accountable for the decision. An agent can prepare the preview, the risk summary, and the readback. The person who confirms owns the outcome, and the audit trail should say so.
A complete safety loop
Use the same loop for every action that triggers a Safety Gate:
The value of these four top-level rules is not that they cover every attack or prove that an Agent will never make a mistake. They separate “what high-capability tools can do” from “what this task is allowed to do,” while giving stronger technical controls a shared authorization language. Low-risk work can therefore proceed continuously, while high-risk consequences pause at the right point for confirmation, execution, and readback.
Safety is not an extra check added after automation is complete. Agent autonomy is truly suitable for production engineering only when permissions are minimal, authorization is specific, boundaries are enforceable, and outcomes are auditable.
Related notes
Making Agent Output Verifiable: Specs, Context, and Checks
Three words separate one person writing code with AI from enterprise-grade delivery: reliable, efficient, sustainable. This piece covers spec-driven development, context engineering, verifiers, and Skill assets, and how the engineering center of gravity has moved from Prompt to Harness.
How My AI Development Workflow Changed: From a Harness to Lightweight Prompts to Enterprise Agents
First a self-built Harness to make up for what models could not do, then a cut down to lightweight Prompts and four gates after Codex 5.6, then the same principles applied to enterprise Agents. What each step removed and kept.
Working on something similar?
I'm always happy to compare notes on distributed systems, delivery, and applied AI.
[email protected]