AI-generated PowerShell script deletes entire hard drive due to path error
A developer lost data when an AI-generated PowerShell script with a path-escaping error wiped a hard drive. Learn the risks of trusting AI code without review.
A developer lost data when an AI-generated PowerShell script with a path-escaping error wiped a hard drive. Learn the risks of trusting AI code without review.
© E. Vartanyan
A routine cleanup task turned into a disaster for one developer when a single incorrect character in an AI-generated script resulted in the complete erasure of data from a hard drive.
The developer explained that he asked an AI to generate a simple PowerShell script to delete Python's pycache folders. Instead, the command wiped the entire contents of an additional drive, including work projects and Docker container data. The story gained attention after being shared on Reddit.
The cause of the failure was surprisingly simple: the generated code contained a path-escaping error, using a backslash where PowerShell required a different character. When PowerShell passed the command through cmd/c, the path was misinterpreted and effectively resolved to the root of the drive. Combined with recursive and silent deletion parameters, the command executed without warnings or confirmation prompts. The system simply began deleting everything in the root directory, leaving the user no chance to stop it.
This highlights that the issue wasn't a complex vulnerability or rare bug, but a subtle difference in how Windows shells handle escaping. Even experienced users can easily miss such nuances, especially when blindly trusting generated code.
The incident illustrates the risks of so-called "vibrocoding"—where developers use AI for quick solutions without thoroughly checking the results. While this approach saves time for harmless operations, the cost of error can be critical when working with the file system.
According to the developer, some data was recovered from backups, but a significant portion was permanently lost. This serves as a clear reminder: any scripts, especially those with forced deletion parameters, require mandatory review and testing in a safe environment.
Artificial intelligence can accelerate workflows, but it doesn't eliminate basic caution. When commands interact directly with the drive, even one misplaced character can have irreversible consequences.