How to Audit an AI Agent's Actions and File Changes
In this article
This guide walks you through auditing what an AI agent did on your system—every command it ran, every file it created, modified, or deleted—so you can verify its work and catch problems early. You'll learn how to set up logging, review the trail, and restore anything that looks wrong. Before starting, make sure you have admin or owner access to the machine or account where the agent runs, and a basic understanding of your operating system's file and process monitoring tools.
What You'll Need
- Access to the terminal or command line (Windows PowerShell, macOS Terminal, or Linux shell).
- Administrator/root privileges to install monitoring tools and read system logs.
- A backup or snapshot of the system state before the agent started, if possible.
- The agent's own logs (if it has any) and its configuration file.
- Optional: a version control system like Git if the agent works on code or documents.
Step-by-Step
- Define the audit scope. Decide what you need to verify: which directories the agent was allowed to touch, which commands it could run, and what time window you're auditing. Write these down—they'll be your baseline.
- Check the agent's built-in logs. Most AI agents (like coding assistants or automation tools) keep a log of their actions. Look in the agent's working directory or its config folder (often
~/.agent-name/logsor%APPDATA%\agent-name\logs). Open the latest log file and note timestamps, commands, and file paths. - Review shell history. If the agent runs commands through a shell, the shell history may contain them. On Linux/macOS, check
~/.bash_historyor~/.zsh_history. On Windows, check PowerShell history with(Get-History)or the PSReadLine history file. Filter for the time window you're auditing. - Enable or check file system auditing. If auditing wasn't enabled before, you can still check current state. For future audits, turn on file system auditing: on Linux, use
auditd; on macOS, usefs_usageor enable Unified Logging; on Windows, enable Object Access Auditing in Group Policy. For now, proceed with what you have. - Use file integrity monitoring. Run a tool like
tripwire,aide, orosqueryto detect changes. If you have a baseline, compare. If not, take a snapshot of the relevant directories now for future comparisons. - Check recently modified files. Use
findwith-mtimeto list files changed in the audit window. Example:find /path/to/project -mtime -1 -type f. On Windows, use PowerShell:Get-ChildItem -Path C:\project -Recurse | Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-1) }. - Compare against version control. If the agent worked in a Git repo, run
git statusandgit diffto see exactly what changed. Usegit log --since="1 day ago"to see commits. This is the most precise way to audit file changes. - Inspect the actual changes. For each changed file, open the diff or the file itself. Look for unexpected deletions, added secrets, or modified permissions. Pay special attention to configuration files, scripts, and anything outside the agent's declared scope.
- Check for new processes or services. The agent might have started background processes. On Linux/macOS, run
ps aux | grep -i agentorsystemctl list-units --type=service. On Windows, check Task Manager orGet-Processin PowerShell. - Review network activity. If the agent made network calls, check its logs or use
netstatorlsof -ito see open connections. This can reveal exfiltration or unexpected API calls. - Document your findings. Create a report listing every action you verified, any anomalies, and whether they match the agent's intended behavior. Include timestamps and file paths.
- Take corrective action. If you find unauthorized changes, restore from backup or use
git checkoutto revert. Kill any rogue processes. Then update the agent's permissions or configuration to prevent recurrence.
Common Mistakes
- Not having a baseline. Without a snapshot of the system before the agent ran, you can't reliably spot changes. Always take a backup or Git commit before letting an agent work.
- Only checking files, not processes. An agent might install a cron job or launch a hidden service. Always check running processes and scheduled tasks.
- Ignoring permission changes. A file can be modified without its content changing—permissions might be altered to allow execution. Use
ls -lato check. - Trusting the agent's own logs blindly. Logs can be incomplete or misleading. Cross-reference with system-level evidence.
- Not checking hidden files. Agents often write dotfiles or config files in hidden directories. Use
ls -aor include hidden files in your search.
Tips
- Run the agent in a sandbox or container (like Docker) so its changes are isolated and easy to discard.
- Use version control for any directory the agent touches, even if it's not code. Git works fine for docs and configs.
- Set up automated file integrity monitoring before you need it. Tools like
inotifywait(Linux) can alert you in real-time. - Keep the audit logs in a separate location that the agent can't modify, like a read-only share or a different user account.
- If you're auditing regularly, script the process. A simple shell script that lists changed files and runs
git diffcan save hours.
Troubleshooting
No logs found. If the agent doesn't keep logs, enable them in its config, or use a system-level monitor like strace (Linux) or dtrace (macOS) to trace its system calls. On Windows, use Process Monitor (Sysinternals) to capture file and registry activity.
File changes are invisible. Some agents write to memory or use in-memory filesystems. Check /tmp or /dev/shm on Linux. Also check if the agent runs as a different user—you may need to switch to that user to see its files.
Changes were made before you enabled auditing. If you have no baseline, you can't know exactly what changed. In that case, focus on verifying the current state is correct and set up monitoring for the future. If you have a recent backup, compare against that.
The agent crashed mid-task. Partial changes may be left behind. Look for temp files or incomplete writes. Run fsck on the filesystem if you suspect corruption. Then re-run the agent from a clean state.
You can't read the logs. Permission denied? Use sudo or Run as Administrator. If logs are encrypted, check the agent's documentation for a decryption key or export option.
Frequently Asked Questions
Q: Can I audit an AI agent that already ran without any prior setup?
A: Yes, but you'll have limited visibility. You can check file modification times, shell history, and running processes. For a thorough audit, you need a baseline, which is why monitoring should be set up before the agent runs.
Q: What's the best tool for file change auditing?
A: For code, Git is the gold standard. For general systems, auditd on Linux, fs_usage on macOS, and Process Monitor on Windows are excellent. For real-time alerts, inotifywait or fswatch work well.
Q: How do I know if the agent accessed the network?
A: Check its logs for API calls, or use lsof -i on Linux/macOS, or netstat -ano on Windows while it's running. If it already finished, look for logs from your firewall or proxy.
Q: Can I prevent an agent from making changes I don't want?
A: Yes. Run it in a container, use a dedicated user with limited permissions, or set up file system permissions that deny writes outside specific directories. Also, review its configuration to restrict allowed actions.
Q: What should I do if I find unauthorized changes?
A: Immediately stop the agent, kill any related processes, and restore the affected files from backup or version control. Then investigate how the agent bypassed your controls and update your security measures.
Q: Is auditing an AI agent different from auditing a human user?
A: Not fundamentally. The same principles apply: track what was done, by whom, and when. The difference is that agents can act very fast and may not follow human patterns, so automated monitoring is even more important.