If a local AI agent runs commands or changes files on your system, you need to verify its actions, contain any risk, and lock down future access. This ensures your data stays safe and your environment remains stable. Start by stopping further unauthorized changes, then audit what was done, and finally restrict the agent’s permissions or isolate it in a sandbox. No special tools are required beyond your operating system’s built-in utilities—Windows Defender, macOS Gatekeeper, Linux sudo logs, and file integrity monitors are all sufficient for basic response.
What You’ll Need
- Administrative access to the machine where the agent runs
- Access to system logs (Event Viewer on Windows, Console on macOS, journalctl on Linux)
- File integrity monitoring tools (optional but recommended: Tripwire, AIDE, or simple checksums via md5sum/sha256sum)
- Time and attention—do not rush the audit
Step-by-Step
- Identify the agent process: Open Task Manager (Windows), Activity Monitor (macOS), or top/htop (Linux). Look for processes with names like “ai-agent”, “local-llm”, “autonomous-agent”, or unfamiliar executables launched by scripts. Note the full path and PID (process ID). If unsure, check startup items or services (e.g., Windows Services.msc > look for non-Microsoft entries), cron jobs (Linux/macOS: crontab -l, /etc/cron.d/), or systemd units (systemctl list-units --type=service).
- Stop the agent immediately: In Task Manager (Windows), right-click the process and choose “End task”. On macOS, click “Quit” in Activity Monitor. On Linux, use `sudo kill
` or `sudo systemctl stop `. If it restarts automatically, disable its startup entry: in Windows, use Task Manager > Startup tab; on macOS, remove from Login Items (System Settings > General > Login Items); on Linux, run `sudo systemctl disable ` and `sudo crontab -e` to remove entries. - Check recent file changes: On Windows, open PowerShell as admin and run `Get-ChildItem -Path C:\ -Recurse -Force -ErrorAction SilentlyContinue | Where-Object { $_.LastWriteTime -gt (Get-Date).AddHours(-2) }` (adjust time window). On macOS, use `find / -type f -mmin -120 2>/dev/null | grep -v "/proc\|/sys"`. On Linux, `find / -type f -mmin -120 2>/dev/null | grep -v "/proc\|/sys"`. Focus on user directories (Documents, Desktop, home), system config paths (/etc, /usr/local), and any known agent install folders. Sort results by date/time to see the most recent changes.
- Review executed commands in logs: On Windows, open Event Viewer > Windows Logs > System and Application logs. Filter for Event IDs 4688 (process creation) and 1 (command-line logging, if enabled). Look for suspicious parent processes like python.exe, node.exe, or unknown scripts launching cmd.exe or powershell.exe. On macOS/Linux, run `journalctl -u
--since "2 hours ago"` or check `/var/log/syslog`/`/var/log/secure`. Also examine shell history: `history` (Linux/macOS), or `Get-History` in PowerShell. - Compare file integrity: For critical directories (e.g., home folder, /etc, /usr/bin), generate checksums: `cd ~ && find . -type f -exec sha256sum {} \; > baseline.sha256`. Later, run `sha256sum -c baseline.sha256` to spot mismatches. Alternatively, use `git status` if the folder is in a Git repo (common for config repos). Flag any unexpected changes—especially to .bashrc, .zshrc, crontabs, or startup scripts.
- Revoke or restrict agent permissions: If the agent uses a user account, ensure it does not run as root/admin. Create a dedicated, low-privilege user (e.g., `sudo adduser --no-create-home ai-agent` on Linux). On Windows, assign it to the “Users” group only. In macOS, remove it from the Administrators group. For file access, apply strict ACLs: Linux (`setfacl -m u:ai-agent:r-- /etc/passwd` to deny write), Windows (Right-click folder > Properties > Security > Advanced > Add > Deny “Modify” for the agent user).
- Sandbox or containerize the agent: For future safety, run the agent inside a restricted environment. On Windows/macOS, use Docker Desktop (enable “Use Docker Compose V2” and create a non-root container with `user: "1000:1000"`). On Linux, use Firejail (`firejail --profile=/etc/firejail/ai-agent.profile`) or systemd’s `ProtectSystem=strict` and `NoNewPrivileges=true` in the unit file. This limits file system access and prevents privilege escalation.
Common Mistakes
- Assuming the agent is safe because it’s “local” or “open-source”—many agents request broad permissions by default.
- Stopping only the process but not disabling auto-start—this causes the agent to reappear after reboot.
- Ignoring hidden files (e.g., .env, .config) where credentials or commands may be stored.
- Deleting files without verifying their purpose first—some changes may be intentional (e.g., agent updating its own config), and deleting them could break your workflow.
- Running agent tools with `sudo` or as admin without understanding the scope—this bypasses OS protections.
Tips
- Run `auditd` (Linux) or enable Windows Audit Policy (Local Policy > Audit Policy) to log future command executions—set `process_creation` auditing.
- Use a separate user account just for AI agents, with no password or login capability (e.g., `usermod -s /usr/sbin/nologin ai-agent`).
- Before granting file access, ask: “Does this agent really need to write to /home/user/Downloads?” Most don’t.
- Test new agents in a VM (VirtualBox/VMware) or container first—snapshots let you revert instantly if things go wrong.
- Keep an offline backup of critical configs (e.g., `/etc` on Linux) so you can restore clean versions if needed.
Troubleshooting
What if the agent keeps restarting? Check for multiple installation paths—e.g., it may be launched by a user script in `~/.bashrc`, a cron job, and a systemd service simultaneously. Search all startup locations: `grep -r "ai-agent" /etc/cron* ~/.config/ ~/.bashrc 2>/dev/null`. What if you can’t identify the executable? Use `lsof -i :