How to Safely Run Autonomous Coding Agents
To safely run autonomous coding agents, add SafeClaw action-level gating. Install with npx @authensor/safeclaw and define a deny-by-default policy that controls every file write, shell command, and network request the agent makes. Autonomous coding agents — Devin, SWE-Agent, OpenHands (formerly OpenDevin), Aider, and similar systems — operate for extended periods without human supervision. They clone repositories, read code, write patches, run tests, install dependencies, execute shell commands, and push changes, all from a single issue description or task prompt.
What Autonomous Coding Agents Can Do (And Why That's Risky)
Fully autonomous coding agents have the broadest capability surface of any AI tool category:
- Full shell access — agents like SWE-Agent and OpenHands run in environments with unrestricted shell access. They execute
git,pip,npm,make,docker,curl, and any other command available in the environment. - Unrestricted file system operations — agents read, write, create, delete, and move files anywhere the OS permissions allow. They modify source code, configuration files, build scripts, CI manifests, and deployment configs.
- Git operations including push — agents clone repos, create branches, commit changes, and push to remotes. A misconfigured agent can force-push to main or push credentials in committed files.
- Package installation — agents install dependencies from public registries. Install scripts from these packages execute with the agent's permissions and can run arbitrary code.
- Network access — agents make HTTP requests for documentation, APIs, and downloads. Generated code can also make network requests at runtime.
- Long-running unsupervised sessions — an autonomous agent might run for 30 minutes to several hours on a single task. During that time, it makes hundreds of individual actions with no human review.
- Multi-step reasoning with tool use — agents plan, execute, observe, and iterate. A single error in the plan can cascade into dozens of unintended actions before the agent recognizes the mistake.
- Environment modification — agents modify shell configuration (
.bashrc,.profile), install system packages, change environment variables, and alter the execution environment itself.
Step-by-Step Setup
Step 1: Install SafeClaw
npx @authensor/safeclaw
For autonomous agents, select SDK Wrapper or Environment Hook depending on the agent framework.
Step 2: Get Your API Key
Visit safeclaw.onrender.com. Free-tier keys renew every 7 days, no credit card.
Step 3: Integration by Agent Type
For SWE-Agent and OpenHands — these agents run in Docker containers or sandboxed environments. Add SafeClaw as an environment-level interceptor:
# In the agent's Docker entrypoint or setup script:
npx @authensor/safeclaw init --mode environment-hook \
--api-key $SAFECLAW_API_KEY \
--policy /workspace/safeclaw.policy.yaml
This installs shell hooks that evaluate every command before execution.
For Devin and cloud-hosted agents — configure SafeClaw as a proxy for the agent's tool calls:
import { SafeClaw } from "@authensor/safeclaw";
const safeclaw = new SafeClaw({
apiKey: process.env.SAFECLAW_API_KEY,
policy: "./safeclaw.policy.yaml",
});
// Wrap the agent's action interface
const guardedActions = {
writeFile: safeclaw.guard("file_write", originalActions.writeFile),
readFile: safeclaw.guard("file_read", originalActions.readFile),
runCommand: safeclaw.guard("shell_exec", originalActions.runCommand),
httpRequest: safeclaw.guard("network", originalActions.httpRequest),
};
For Aider — Aider operates through git and file edits. Wrap its file operations:
# Run Aider with SafeClaw environment hooks active
npx @authensor/safeclaw exec -- aider --model gpt-4
Step 4: Define Your Policy
This policy is restrictive by design — autonomous agents need tight boundaries:
version: 1
default: deny
rules:
# File reads: project directory only
- action: file_read
path: "${PROJECT_DIR}/**"
effect: allow
- action: file_read
path: "*/.env"
effect: deny
- action: file_read
path: "/.ssh/"
effect: deny
- action: file_read
path: "**/.git/config"
effect: deny
- action: file_read
path: "*/secret*"
effect: deny
- action: file_read
path: "*/credential*"
effect: deny
# File writes: source and tests only
- action: file_write
path: "${PROJECT_DIR}/src/**"
effect: allow
- action: file_write
path: "${PROJECT_DIR}/tests/**"
effect: allow
- action: file_write
path: "${PROJECT_DIR}/test/**"
effect: allow
- action: file_write
path: "${PROJECT_DIR}/.github/**"
effect: deny
- action: file_write
path: "${PROJECT_DIR}/Dockerfile"
effect: deny
- action: file_write
path: "**/.bashrc"
effect: deny
- action: file_write
path: "**/.profile"
effect: deny
# Shell commands: explicit allowlist
- action: shell_exec
command: "python*"
effect: allow
- action: shell_exec
command: "node*"
effect: allow
- action: shell_exec
command: "npm test*"
effect: allow
- action: shell_exec
command: "npm run build*"
effect: allow
- action: shell_exec
command: "git diff*"
effect: allow
- action: shell_exec
command: "git status"
effect: allow
- action: shell_exec
command: "git add*"
effect: allow
- action: shell_exec
command: "git commit*"
effect: allow
- action: shell_exec
command: "git push --force*"
effect: deny
- action: shell_exec
command: "rm -rf*"
effect: deny
- action: shell_exec
command: "pip install*"
effect: deny
- action: shell_exec
command: "npm install*"
effect: deny
- action: shell_exec
command: "curl*"
effect: deny
- action: shell_exec
command: "wget*"
effect: deny
- action: shell_exec
command: "chmod*"
effect: deny
- action: shell_exec
command: "chown*"
effect: deny
- action: shell_exec
command: "sudo*"
effect: deny
# Network: deny all by default
- action: network
host: "api.openai.com"
effect: allow
- action: network
host: "api.anthropic.com"
effect: allow
- action: network
host: "*"
effect: deny
Step 5: Simulate Extensively
npx @authensor/safeclaw simulate --policy safeclaw.policy.yaml
Run the agent against several test tasks. Autonomous agents generate high volumes of actions — review the full simulation log before enforcing. Pay particular attention to multi-step chains where one blocked action might cause the agent to try alternative (and potentially riskier) approaches.
What Gets Blocked, What Gets Through
ALLOWED — Agent reads source code:
{ "action": "file_read", "path": "/project/src/utils/parser.py", "verdict": "ALLOW" }
DENIED — Agent reads git credentials:
{ "action": "file_read", "path": "/home/agent/.git/config", "verdict": "DENY", "reason": "path matches **/.git/config deny rule" }
ALLOWED — Agent commits its changes:
{ "action": "shell_exec", "command": "git commit -m 'Fix parser edge case'", "verdict": "ALLOW" }
DENIED — Agent tries sudo:
{ "action": "shell_exec", "command": "sudo apt-get install libxml2-dev", "verdict": "DENY", "reason": "sudo* matches deny rule" }
DENIED — Agent curls external endpoint:
{ "action": "network", "host": "pastebin.com", "verdict": "DENY", "reason": "host not in allowlist, default deny" }
Without SafeClaw vs With SafeClaw
| Scenario | Without SafeClaw | With SafeClaw |
|---|---|---|
| Agent runs for 2 hours, executes 300+ actions | All 300+ actions execute without review | Each action individually evaluated — policy violations blocked in real time |
| Agent installs a dependency with a malicious postinstall script | Package installed, script executes | Blocked — npm install and pip install match deny rules |
| Agent modifies .bashrc to add PATH entries | Shell config changed, persists across sessions | Blocked — **/.bashrc is denied for writes |
| Agent reads .ssh/id_rsa for git authentication context | Private key loaded into agent context | Blocked — /.ssh/ is denied for reads |
| Agent writes fix to src/utils/parser.py | File written normally | Allowed — src/** is in write allowlist |
SafeClaw evaluates every action in sub-millisecond time, adding negligible overhead even for agents executing hundreds of actions per session. The tamper-proof audit trail (SHA-256 hash chain) provides a complete record of every action and verdict. The control plane sees only action metadata — never your repository code, credentials, or agent configuration. SafeClaw runs with zero third-party dependencies, is validated by 446 tests under TypeScript strict mode, and the client is 100% open source (MIT license).
Cross-References
- What is SafeClaw? — Deny-by-default action gating fundamentals
- How to Safely Use Claude Code — Claude Code as a coding agent with SafeClaw
- How to Safely Run AutoGen Agents — AutoGen code executors with policy gating
- How to Safely Run LangChain Agents — LangChain tool wrapping patterns
- How to Safely Run MCP Tool Servers — MCP tool gating for agents using MCP
Try SafeClaw
Action-level gating for AI agents. Set it up in your browser in 60 seconds.
$ npx @authensor/safeclaw