{"record":{"id":"6ced4ad7c409aeb8","repo":"hashicorp/vagrant","slug":"vagrant-attempted-to-clean-the-machine-folder-for","errorCode":null,"errorMessage":"Vagrant attempted to clean the machine folder for the machine '%{name}'\nbut does not have permission to read the following path:\n\n%{path}\n\nPlease ensure that Vagrant has the proper permissions to access the path\nabove. You may need to grant this permission to the terminal emulator\nrunning Vagrant as well.","messagePattern":"Vagrant attempted to clean the machine folder for the machine '%(.+?)'\nbut does not have permission to read the following path:\n\n%(.+?)\n\nPlease ensure that Vagrant has the proper permissions to access the path\nabove\\. You may need to grant this permission to the terminal emulator\nrunning Vagrant as well\\.","errorType":"exception","errorClass":"Vagrant::Errors::MachineFolderNotAccessible","httpStatus":null,"severity":"error","filePath":"plugins/providers/virtualbox/action/clean_machine_folder.rb","lineNumber":24,"sourceCode":"module VagrantPlugins\n  module ProviderVirtualBox\n    module Action\n      # Cleans up the VirtualBox machine folder for any \".xml-prev\"\n      # files which VirtualBox may have left over. This is a bug in\n      # VirtualBox. As soon as this is fixed, this middleware can and\n      # will be removed.\n      class CleanMachineFolder\n        def initialize(app, env)\n          @app = app\n        end\n\n        def call(env)\n          machine_folder = env[:machine].provider.driver.read_machine_folder\n\n          begin\n            clean_machine_folder(machine_folder)\n          rescue Errno::EPERM\n            raise Vagrant::Errors::MachineFolderNotAccessible,\n              name: env[:machine].name,\n              path: machine_folder\n          end\n\n          @app.call(env)\n        end\n\n        def clean_machine_folder(machine_folder)\n          folder = File.join(machine_folder, \"*\")\n\n          # Small safeguard against potentially unwanted rm-rf, since the default\n          # machine folder will typically always be greater than 10 characters long.\n          # For users with it < 10, out of luck?\n          return if folder.length < 10\n\n          Dir[folder].each do |f|\n            next unless File.directory?(f)\n","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/plugins/providers/virtualbox/action/clean_machine_folder.rb#L6-L42","documentation":"During VirtualBox cleanup (the CleanMachineFolder action runs before destroy/re-up), Vagrant globs the VirtualBox default machine folder and deletes leftover per-VM subfolders. If any file operation underneath raises Errno::EPERM, it is rescued and re-raised as MachineFolderNotAccessible with the offending folder path. The intent is to abort with a clear message instead of a raw EPERM backtrace.","triggerScenarios":"`vagrant destroy` or `vagrant up` on VirtualBox where File.delete/FileUtils operations inside clean_machine_folder(machine_folder) hit EPERM — files owned by another user, locked by a process, or on a directory the current user cannot read.","commonSituations":"VMs originally created from an elevated/admin terminal and now cleaned from a normal one; antivirus or backup software holding handles on .vbox/.vdi files; the default machine folder moved onto OneDrive/protected storage on Windows; POSIX-inherited ownership after copying VM folders between users.","solutions":["Run the same vagrant command from an elevated (Administrator) terminal or the same user that created the VMs","Fix ownership/ACLs on the printed path: `takeown /f \"<path>\" /r` + `icacls \"<path>\" /grant <user>:(OI)(CI)F` on Windows, or `sudo chown -R $USER <path>` on Unix hosts","Exclude the VirtualBox machine folder (default ~/VirtualBox VMs) from antivirus real-time scanning and OneDrive sync","As a last resort delete the stale subfolder manually, then re-run vagrant destroy/up"],"exampleFix":"# before: normal shell, files owned by admin\n# vagrant destroy -> MachineFolderNotAccessible path=C:\\Users\\admin\\VirtualBox VMs\n\n# after (Windows, elevated PowerShell):\n# takeown /f \"C:\\Users\\admin\\VirtualBox VMs\" /r\n# icacls \"C:\\Users\\admin\\VirtualBox VMs\" /grant youruser:(OI)(CI)F /t\n# vagrant destroy","handlingStrategy":"try-catch","validationCode":"# confirm the default machine folder is writable before destroy/up\nfolder = `VBoxManage list systemproperties`[/Default machine folder:\\s+(.+?)\\n/, 1].to_s.strip\nraise \"Not writable: #{folder}\" unless File.writable?(folder)\n# deeper probe (Windows may allow File.writable? but deny delete):\nprobe = File.join(folder, '.vagrant_probe')\nFileUtils.touch(probe); FileUtils.rm(probe) rescue raise \"EPERM expected under #{folder}\"","typeGuard":null,"tryCatchPattern":"begin\n  machine.action(:destroy)\nrescue Vagrant::Errors::MachineFolderNotAccessible => e\n  warn \"Fix ACLs on #{e.extra_data[:path]} (takeown/icacls), delete stale folders manually, then retry\"\n  # safe to continue: cleanup failed but the destroy itself can be retried\nend","preventionTips":["Create and destroy VMs from the same (non-admin) user session consistently","Move the VirtualBox machine folder off OneDrive/managed/AV-scanned paths","Add an AV exclusion for the machine folder in your workstation baseline"],"tags":["virtualbox","permissions","eperm","cleanup","filesystem"],"backgroundTag":"permission-denied","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}