How to Monitor AI Agents for Unexpected File Changes
In this article
Monitoring AI agents for unexpected file and system changes means setting up a baseline of what is normal, then using file integrity monitoring, audit logs, and change detection alerts to catch deviations. You do not need enterprise tools to start: a checksum manifest, the operating system's built-in auditing, and a scheduled comparison script will cover most small deployments. The goal is to know within minutes, not days, when an agent writes outside its sandbox, modifies configuration files, or touches system paths it should never reach.
What You'll Need
- A dedicated user account or container for each AI agent, so its actions are attributable.
- File integrity monitoring software or a simple checksum tool such as sha256sum (Linux/macOS) or Get-FileHash (Windows PowerShell).
- Access to the operating system's audit subsystem: auditd on Linux, the Security log with Object Access auditing on Windows, or the unified log on macOS.
- A place to store baselines and logs that the agent cannot write to (a separate volume, a remote syslog server, or a write-once bucket).
- An alerting channel such as email, a chat webhook, or your existing monitoring dashboard.
Step-by-Step
- Isolate the agent first. Run each AI agent under its own low-privilege account, container, or virtual machine. Give it write access only to the directories it genuinely needs. This single step makes every later detection meaningful, because any write outside the allowed paths is by definition unexpected.
- Define the watch list. Write down the paths that matter: system binaries (/usr/bin, /bin, C:\Windows\System32), configuration files (/etc, C:\ProgramData), startup locations (systemd unit files, cron jobs, Windows services and scheduled tasks), and the agent's own working directory. Keep the list short and specific; monitoring everything produces noise you will learn to ignore.
- Capture a baseline. With the agent stopped, record the state of the watch list. On Linux or macOS:
find /etc /usr/bin -type f -exec sha256sum {} \; > baseline.txt. On Windows PowerShell:Get-ChildItem C:\Windows\System32 -Recurse -File | Get-FileHash | Export-Csv baseline.csv. Store the baseline where the agent cannot modify it. - Enable system auditing. On Linux, install and start auditd, then add rules that log writes to your watch list, for example
auditctl -w /etc -p wa -k agent_etc_write. On Windows, open the Local Security Policy, enable Audit Object Access under Advanced Audit Policy, then set auditing on the specific folders through their Properties > Security > Advanced > Auditing tab. On macOS, usesudo fs_usagefor live inspection or configure the unified log to capture file operations. Menu labels vary slightly by OS version and edition. - Schedule regular comparisons. Run a script every few minutes that recomputes hashes and diffs them against the baseline. A cron job or Windows Task Scheduler entry is enough. Have the script exit non-zero and send an alert when any hash changes, a new file appears in a protected path, or a watched file is deleted.
- Watch process and network behaviour too. File changes rarely happen alone. Log the processes each agent spawns and the outbound connections it makes. On Linux, auditd's execve rules and tools like auditbeat or osquery can record both. Sudden shell spawns from an agent process or connections to unfamiliar hosts are strong signals that something is wrong.
- Route alerts to a human. Send integrity alerts to a channel someone actually reads. Include the file path, the old and new hash, the timestamp, and the user account responsible. Without the account name you cannot tell an agent from an administrator.
- Review and re-baseline deliberately. When you intentionally update software or configuration, regenerate the baseline as part of that change and record why. Never re-baseline just to silence an alert you have not explained.
Common Mistakes
- Running the agent as root or Administrator, which makes every change look authorised and destroys attribution.
- Storing the baseline or logs in a directory the agent can write to; a compromised or misbehaving agent can then hide its own tracks.
- Monitoring entire disks instead of specific paths, generating so much noise that real alerts are missed.
- Relying only on file hashes and ignoring process creation, scheduled tasks, and network connections, which often reveal the cause of a change.
- Re-baselining automatically after every alert, which turns the monitoring into a rubber stamp.
- Forgetting that containerised agents can write to mounted volumes on the host; those mounts must be in the watch list.
Tips
- Give each agent a read-only root filesystem where possible and a single writable scratch directory.
- Keep baselines and audit logs on a separate host or a remote log service so they survive tampering.
- Test the alert path by deliberately touching a watched file; if no alert arrives, fix that before trusting the system.
- Tag alerts by agent identity so you can see which agent is responsible at a glance.
- Review audit rules after OS upgrades, since package updates can legitimately change binaries and trigger a burst of alerts.
Troubleshooting
No alerts arrive at all. Check that the comparison script actually runs on schedule and that its output is captured. Run it manually and confirm it detects a test change. Then verify the alert transport (webhook, SMTP, dashboard) independently.
Too many alerts. Narrow the watch list, exclude known-volatile paths such as caches and temporary directories, and raise the comparison interval. If a specific file changes constantly, investigate why rather than excluding it blindly.
Alerts with no user account. Auditing is probably not enabled on that path, or the log format does not include the responsible user. Re-check the audit rule and confirm the agent is not running under a shared account.
Hashes differ but files look identical. Timestamps and metadata may be changing without content changes. Compare content hashes only, and check whether a backup or sync tool is rewriting files.
Audit log fills the disk. Configure log rotation and retention for auditd or the Windows Security log, and keep only the rules you need.
Frequently Asked Questions
Do I need commercial software to monitor AI agents?
No. Built-in auditing plus a scheduled checksum comparison covers small setups. Commercial file integrity monitoring adds central management and tamper-resistant storage, which helps as the number of agents grows.
How often should I compare baselines?
Every few minutes for sensitive paths such as system binaries and configuration; hourly is usually enough for less critical directories. The right interval is the longest one that still lets you react before damage spreads.
Can I monitor agents running in containers?
Yes, but watch the host paths that are mounted into the container. Changes made inside an ephemeral container layer disappear on restart, so persistent mounts and volumes are what you need to baseline and audit.
What counts as an unexpected change?
Any write, creation, or deletion in a watched path that was not part of a planned update, plus any change made by an account other than the one you expected. Process spawns and outbound connections from the agent are also worth alerting on.
Will this slow the agent down?
Hashing a small watch list takes seconds and auditing adds modest overhead. Monitoring entire disks is what causes noticeable slowdown, which is another reason to keep the list targeted.