See how real agent mistakes lead to data loss, which safeguards help, and where to look for recoverable files on a Mac.. .
Table of Contents
TL;DR
AI agents can delete data through the tools and credentials you give them. Recovery depends on whether a checkpoint, file history, backup, or readable copy survives.
-
Risk: Broad permissions can turn a routine cleanup into permanent data loss.
-
Prevention: Restrict access, review destructive actions, and protect backups from the agent.
-
Recovery: Stop the task, check saved versions, and scan local storage only when needed.
Introduction
In April 2026, an AI agent deleted a customer’s production database on Railway using an API token it found on the user’s computer. Railway’s incident report explains that the request was authenticated, so the API executed it. The provider later recovered the database, but the incident exposed how ordinary credentials could turn an agent’s mistake into a business outage.
Smaller losses can be just as painful. A Claude Code user reported on GitHub that an unsolicited cleanup deleted existing documents whose names matched a filename pattern. If you’re testing or deploying agents, you need to know how to limit what they can change and which recovery options remain when something goes wrong.
Can AI Agents Actually Delete Files?
So, can AI agents delete files? Yes, when their connected tools and permissions allow it. A terminal can execute deletion commands, while an API can remove database records or cloud storage. The system checks authorization, not whether the action matches your intent.
The deletion method also matters for recovery. A file moved to the Mac’s Trash may be easy to restore, while a terminal command can bypass Trash entirely. Data stored only in the cloud must be recovered through the hosting service or its backups; scanning your Mac won’t retrieve it.
Common AI Agent Security Risks
AI agent security risks become clearer when you look at what went wrong in reported incidents:
-
Excessive permissions. Excessive permissions can give an agent access to resources unrelated to its task. In the Railway incident, an account-scoped token allowed the agent to reach production storage. Leaving powerful credentials in project files can therefore expose more than the folder you intended to share. Destructive commands with the wrong scope. In the Claude Code report, a cleanup used a wildcard, a pattern matching multiple filenames. It also matched unrelated documents. The user reported that no confirmation appeared. Reviewing the actual file list matters more than approving a vague “cleanup.”
-
Confusion between test and production environments. Similar resource names and shared credentials can let a test reset reach live data. Railway’s account describes deletion being chosen to fix an unrelated problem. The agent’s intended task did not make the selected production volume safe to remove.
-
Overwriting files you still need. A refactor or document update can replace useful content without deleting the file. Review the changes before accepting them, and keep earlier versions. A file’s continued existence does not mean its original contents survived.
How to Prevent AI Agents from Deleting Files
To prevent AI agents from deleting files, enforce limits through permissions and tool settings. A prompt such as “never delete anything” should not be your only protection.
-
Limit access to what the task requires. Use read-only access for reviews and analysis. When edits are necessary, restrict the agent to the relevant folder or project. Keep production credentials out of development environments.
-
Work in an isolated environment. Test changes on copies or in a sandbox. Keep live database credentials and original files out of that environment; a separate folder alone does not prevent access to connected services.
-
Review destructive actions before execution. Require approval for deletions, overwrites, and database changes where supported. Check the exact paths, affected records, and target environment. An approval for “clean up the project” gives you too little information.
-
Keep backups outside the agent’s reach. Use separate credentials and a protected backup destination. Time Machine can protect local Mac files; production databases need their own backups. Ensure the agent cannot delete the recovery copies.
-
Check that recovery works. Restore a sample file or test a database restore in a separate environment. Confirm that the recovered data opens correctly and that the backup includes the files and recent changes you need.
Commit working code before a major agent task, and back up files outside version control.
How to Recover Files Deleted by an AI Agent
Stop the Agent and Check Recovery Options
Stop the task and revoke the agent’s write access. Check its logs for affected paths and commands. For local losses, minimize writes to the drive: don’t download software or save recovered files there.
If you were using Cursor or Claude Code before the deletion, check whether the agent saved an earlier version of your files. Look for Cursor’s Restore Checkpoint or try Claude Code’s /rewind. These cover tracked file changes, not every action: Claude Code cannot rewind a file changed only through Bash if its file-editing tools never tracked it. If your project uses Git and the missing files were saved in an earlier commit, you can restore them from that version. For files never committed, JetBrains Local History may retain a recoverable version; right-click the parent folder and choose Local History > Show History.
For production databases or cloud resources, use the affected service’s recovery system with your administrator or provider. Look for database point-in-time recovery, snapshots, object versioning, or retained deleted items. A local code checkpoint cannot restore a remote database. Where possible, restore into a test environment and verify the result before using it in production.
Check Trash, Backups, and Version History
To recover accidentally deleted files on Mac, start with the copies that may already exist:
-
Trash: Open Trash from the Dock, find the file, right-click it, and choose Put Back. This only works if the deletion moved it to Trash and it hasn’t been emptied. Files removed through terminal commands may never appear there.

-
Time Machine: If a backup exists, connect the backup disk and open the folder where the file was stored. Enter Time Machine, browse to a date before the deletion, select the item, and click Restore.

-
Version history and cloud recovery: Check the document application’s version history after an overwrite. For synced files, look in the cloud service’s deleted-items area.
If Trash is empty, it’s still worth checking for copies elsewhere. You’ll find similar advice from Mac users: check iCloud’s Recently Deleted area if the files were synced there, along with any existing backups, before turning to recovery software.
Verify that the restored version includes the changes you need.
Try Data Recovery Software When No Copy Is Available
If no usable copy exists, recovery software can scan the drive for remaining file data. To recover files deleted by AI, you use the same tools as for files deleted manually.
Your storage device matters. USB flash drives and internal or external hard drives may still contain recoverable data. On SSDs, including internal Mac storage, TRIM can make deleted data unrecoverable. Software also cannot reconstruct content that has already been overwritten.
If an external drive disconnects or isn’t detected, try another port or cable. If problems persist, or an HDD makes unusual clicking sounds, stop using it and contact a professional data recovery service before scanning.
When comparing the best data recovery software for Mac users, check support for your drive’s file system, file previews, and recovery costs. Disk Drill is one option you can use to scan for lost files:
-
Install Disk Drill on an unaffected drive. If the files were on your Mac’s startup disk, minimize use of that Mac. Disk Drill can also run from an external drive or through macOS Recovery, so you don’t have to install it on the affected disk.
-
Open the app, select the affected drive, and let the scan finish.

-
Review the scan results and, where available, preview the files you need to check their contents. File previews aren’t available when Disk Drill runs in macOS Recovery.

-
Select the files and recover them to a different drive.

After recovery, open the files and check their contents. Review the agent’s logs to find the command, path, or permission that caused the loss, then correct it. Run the task again on a test copy with restricted access before resuming normal work.
Final Thoughts
AI agents can delete production data and local files through legitimate tools. Limit their permissions, review destructive changes, and keep protected backups. Checkpoints and file history offer useful recovery options, but their coverage has limits.
Before your next agent task, identify which copy you would restore and test that route. If no usable backup is available, recovery software can help retrieve deleted files while their data remains on the drive.


Leave a Reply