Table of Contents
AI coding agents can inspect a repository, edit files, run commands, and sometimes access the network. That makes them more capable than a chat assistant—and gives mistakes or malicious instructions a larger blast radius. The safest approach is to combine least-privilege permissions, an isolated workspace, restricted credentials and network access, and a human-controlled review and deployment process.

Start by defining what the agent is allowed to touch
Before opening Claude Code, Codex, or another coding agent, decide what the task actually requires. A documentation edit may need access only to one repository and no network connection. A dependency upgrade may need limited package-registry access, but it still should not need production credentials or administrator privileges.
Use a dedicated branch or worktree and begin from a clean Git status. Commit or back up valuable local changes first. If the repository is unfamiliar, inspect its setup scripts, agent instruction files, hooks, and package scripts before letting an agent run them. Text inside a repository, issue, webpage, dependency, or tool response can contain instructions that should be treated as untrusted input.
Apply least privilege
- Give write access only to the project directory needed for the task.
- Keep personal folders, unrelated repositories, SSH keys, browser profiles, cloud configuration, and password stores outside the readable or writable boundary.
- Use short-lived, narrowly scoped tokens when authentication is unavoidable.
- Do not expose production database passwords, signing keys, deployment tokens, or unrestricted cloud credentials.
- Disable network access by default, or allow only the domains required for the task.
- Run the agent as a normal user, not as root or an administrator.
OpenAI's Codex security guidance describes sandboxing and approvals as separate controls: the sandbox limits what commands can access, while the approval policy determines when the agent must stop and ask. Anthropic's Claude Code security documentation likewise recommends reviewing commands and using filesystem and network isolation.
Use an isolated environment for higher-risk work
A container, development container, disposable virtual machine, or short-lived cloud workspace can reduce the impact of a bad command. Isolation is especially useful when testing installation scripts, evaluating an unfamiliar repository, running generated code, or allowing longer autonomous sessions.
Isolation is not automatic safety. A container with the host filesystem broadly mounted, unrestricted network access, or valuable secrets inside it can still expose those resources. Mount only the working repository, avoid forwarding a full SSH agent, and supply only the minimum credentials required. Recreate the environment after suspicious behavior instead of trusting a possibly altered workspace.
If you need a dedicated virtual machine for experimentation, TipsMake's overview of isolated AI-agent use provides additional context on why separation matters. The specific controls will differ by tool, but the principle is the same: do not place an autonomous process in the same trust zone as irreplaceable data.
Treat permission prompts as security decisions
Default or approval-based modes are the right starting point. Read the exact command, its working directory, the files it can affect, and whether it will make a network request. Approve the narrowest scope that lets the task continue; a one-time approval is safer than a permanent rule when you are uncertain.
Do not rely on a block list containing only commands such as rm -rf. Files can be overwritten, moved, encrypted, uploaded, or deleted through many commands, scripts, programming languages, package managers, and application APIs. A command can also be harmless by itself but dangerous because of shell expansion, redirected output, an altered working directory, or an untrusted script it invokes.
When should bypass-permission modes be used?
Claude Code's --dangerously-skip-permissions option and Codex configurations that bypass approvals or grant full access remove important safety boundaries. They should not be the normal way to save time. If a task genuinely requires unattended execution, run it only in a disposable environment that contains no valuable secrets, has tightly scoped filesystem mounts and network access, and cannot deploy directly to production.
Even in a sandbox, monitor the session and keep an audit trail. A malicious project can attempt to exfiltrate anything available inside the environment, including credentials placed there for convenience.
Review the result, not just the final message
An agent saying that a task is complete is not evidence that the change is correct. Inspect the full diff and look for unrelated edits, disabled checks, weakened error handling, hard-coded secrets, unexpected network calls, and changes to build or deployment configuration.
A practical review sequence is:
- Read the plan and changed-file list. Confirm that the scope matches the request.
- Inspect the diff. Pay special attention to authentication, authorization, input handling, data access, migrations, dependencies, and infrastructure files.
- Run project checks. Use the repository's formatter, linter, type checker, tests, and build process in the isolated environment.
- Test failure paths. Verify invalid input, denied access, timeouts, partial failures, and rollback behavior—not only the happy path.
- Review dependency changes. Check the lockfile, package source, install scripts, and whether the new dependency is actually necessary.
- Scan for secrets and security regressions. Automated tools can help, but investigate findings rather than accepting or dismissing them blindly.
A second AI reviewer can catch omissions and provide a useful independent pass, but it should not be the only gate for high-impact code. Human review remains important for security controls, payment flows, personal data, production infrastructure, database migrations, compliance-sensitive logic, and changes whose business requirements are not fully encoded in tests. For a broader comparison of agent-enabled development tools, see TipsMake's Cursor and GitHub Copilot comparison.
Keep production behind a separate control plane
A coding agent generally should prepare a change, not deploy it with unrestricted production access. Use protected branches, pull requests, required checks, code-owner review, staged rollouts, and an approved CI/CD path. Separate development credentials from production credentials, and require a human or tightly controlled automation step for releases.
For database or infrastructure work, create a backup or verified recovery point, rehearse the change in staging, document the rollback procedure, and confirm that monitoring is in place. If an agent needs logs to diagnose a problem, provide a redacted, read-only view instead of broad access to production systems.
A safe operating checklist
- The task and repository are trusted and clearly scoped.
- Work starts on a separate branch or worktree with recoverable changes.
- Filesystem access is limited to the required project.
- Network access is off or restricted to approved destinations.
- No production or long-lived credentials are available to the agent.
- High-risk commands require explicit review.
- The complete diff, dependencies, tests, and failure paths are checked.
- Deployment remains behind protected, auditable controls.
- There is a backup and rollback plan for consequential changes.
If the agent behaves unexpectedly, stop the session, preserve relevant logs, inspect the diff and command history, and rotate any credential it may have accessed. Rebuild a disposable environment rather than continuing in a workspace whose integrity is uncertain.
Reader Comments 0
Sign in with email or Google to join the discussion.