keepcalculator

06 Numbers and Powers

Stop an AI Coding Agent From Running Risky Commands

Card No. 06·29155 · Updated · Standard formula, shown below

An AI coding agent can save time, but a mistaken shell command may delete files, expose secrets, or change a system outside the project. You can reduce that risk by limiting its permissions, requiring approval for consequential commands, and keeping a recoverable copy of your work; no setting can make an agent completely risk-free.

What You’ll Need

  • Access to the coding agent’s settings, command approval controls, or project configuration.
  • A clear idea of which folders and tools the agent needs for its task.
  • A backup or version-control checkpoint for important work.
  • If available, a disposable development environment such as a container or virtual machine.

Step-by-Step

  1. Protect the current project first. Save your work and create a commit, branch, or separate backup before granting the agent access. Check that the backup is usable and does not contain credentials you would not want copied elsewhere. Version control helps recover tracked files, but it does not necessarily restore untracked files, external data, or system settings.
  2. Find the agent’s execution controls. Open its settings or project instructions and look for options named along the lines of command approval, tool permissions, terminal access, or execution policy. Names differ between products. Read the description before changing a control; do not assume that “read-only” prevents every side effect if the agent can still access a shell or other tools.
  3. Choose approval before execution. Set the agent to ask before running commands, rather than automatically approving all commands, if that option exists. Review each proposed command and its working directory before approving it. If the product supports separate policies, allow low-risk inspection while keeping file changes, package installation, network access, and system-level operations subject to approval.
  4. Restrict the working area. Open only the repository or folder needed for the task. Avoid launching the agent from your home folder, a drive root, or a directory containing unrelated work. Where supported, use a workspace boundary or sandbox that prevents access to files outside the project. A folder boundary is useful only if the tool actually enforces it; check the product’s documentation.
  5. Make the task’s boundaries explicit. In the project instructions or task prompt, say which files may be changed and which actions need permission. For example: “Inspect the project and suggest a fix. Do not delete files, install packages, access the network, or run commands that change system settings without asking.” This guides behavior but is not a security control by itself, so keep enforced permissions in place.
  6. Block especially destructive operations where possible. Use a deny list or policy for commands that recursively delete files, overwrite broad paths, change permissions, modify system configuration, or run scripts from untrusted sources. Avoid relying on a short list of command names alone: shells can express the same action in different ways, and scripts may hide risky operations. Prefer approval for the action or tool category, plus a restricted environment.
  7. Use a disposable environment for uncertain work. Run the agent in a container, virtual machine, or separate development environment when practical. Give it only the project files and resources it needs. Do not mount sensitive folders or pass through privileged access unless essential. A container is not automatically isolated if it has broad host mounts, elevated privileges, or access to the host’s control socket.
  8. Review commands in context before approving. Check the full command, its arguments, directory, and likely effects. Be cautious with recursive flags, wildcards, pipes, command substitution, administrator privileges, remote downloads, and scripts whose contents you have not inspected. If you cannot explain what a command will do, deny it and ask the agent for a safer, narrower alternative.
  9. Keep secrets and network access limited. Remove unnecessary API keys and credentials from the environment, and avoid opening secret files to the agent. If network access is not needed, disable it through the environment or tool policy. If it is needed, review package sources and downloaded scripts rather than allowing unrestricted retrieval and execution.
  10. Verify the result and tighten settings afterward. Inspect the changes with a diff or file review, run appropriate tests yourself, and check for unexpected files or configuration changes. Revoke temporary permissions and remove disposable credentials when the task ends. If anything unexpected happened, stop the agent before continuing.

Common Mistakes

  • Trusting a prompt as a security boundary. Instructions can reduce unwanted actions, but a model may misunderstand or ignore them. Use product-level permissions and isolation as well.
  • Approving a command because it looks familiar. A harmless-looking command can include a destructive argument, run from the wrong directory, or invoke a script with additional behavior. Review the entire command and context.
  • Allowing every command to avoid interruptions. Blanket approval removes a valuable checkpoint. Start with approval required, then allow only narrow, understood operations if repeated prompts are slowing routine work.
  • Assuming a backup covers everything. A source-control commit may omit ignored, untracked, generated, or external data. Confirm what must be restored and back up it separately.
  • Giving a sandbox broad host access. A container or virtual machine offers little protection if it can modify the host through mounted folders, shared credentials, or elevated permissions.

Tips

  • Use a dedicated development account with only the access needed for the project.
  • Ask the agent to explain a proposed command and identify files it expects to change before approving it.
  • Prefer narrow operations, such as targeting a specific project folder, over broad recursive changes.
  • Keep approval prompts enabled for deletion, installation, network access, and system-level changes.
  • Check the agent’s documentation for how permissions apply to terminal commands, scripts, plugins, and background tasks; controls may not cover every tool equally.

Troubleshooting

The agent still runs commands without asking: Stop the session and look for a separate auto-approval, trusted-command, or unattended-execution setting. Confirm whether the policy applies to the current workspace and restart the session after changing it. If there is no reliable approval control, do not use the agent with access to important files; move the work to an isolated environment or choose a tool with enforceable restrictions.

A denied command keeps returning: Keep denying it and ask for a plan that uses permitted actions. Do not approve a renamed or split-up version without understanding its effect. If the command is genuinely required, inspect its source and run it yourself only after confirming the scope and recovery plan.

The agent cannot complete a legitimate task: Identify the smallest missing permission, grant it temporarily if the product supports that, and keep approval enabled for consequential actions. Avoid switching to unrestricted access. If a setting has unclear effects, consult the tool’s documentation or administrator.

Unexpected files changed or disappeared: Stop further execution. Preserve logs and inspect the project’s status and recent changes. Restore from a known-good commit or backup only after checking which files would be replaced; a broad restore can discard useful work. If credentials may have been exposed, revoke or rotate them using the service that issued them.

Frequently Asked Questions

Can I guarantee that an AI coding agent will never run a risky command?
No. You can reduce the chance and limit the impact with enforced permissions, approval gates, and isolation, but inspect the controls and maintain backups.

Is asking the agent not to run commands enough?
No. A prompt is an instruction, not a technical restriction. Pair it with execution controls and limited access.

Should I disable terminal access completely?
Do so if the task does not need command execution. If it does, allow only the necessary tools and require review for actions with side effects.

What commands should always require review?
Review commands that delete or overwrite files, change permissions or system settings, install software, access networks, or use elevated privileges. Consider scripts and pipelines by what they do, not just their names.

Does running an agent in a container make it safe?
It can limit damage, but only when configured with restricted mounts, privileges, credentials, and network access. It is not a substitute for command review or backups.

What should I do after accidentally approving a risky command?
Stop the session, inspect its effects, and restore only the affected files from a verified backup. Revoke exposed credentials and review permissions before resuming.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →