{"record":{"id":"7496af6e65cd8079","repo":"lima-vm/lima","slug":"instance-is-protected-to-prohibit-accidental-remov","errorCode":null,"errorMessage":"instance is protected to prohibit accidental removal (Hint: use `limactl unprotect`)","messagePattern":"instance is protected to prohibit accidental removal \\(Hint: use `limactl unprotect`\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/instance/delete.go","lineNumber":19,"sourceCode":"// SPDX-FileCopyrightText: Copyright The Lima Authors\n// SPDX-License-Identifier: Apache-2.0\n\npackage instance\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/lima-vm/lima/v2/pkg/driver/external/server\"\n\t\"github.com/lima-vm/lima/v2/pkg/driverutil\"\n\t\"github.com/lima-vm/lima/v2/pkg/limatype\"\n)\n\nfunc Delete(ctx context.Context, inst *limatype.Instance, force bool) error {\n\tif inst.Protected {\n\t\treturn errors.New(\"instance is protected to prohibit accidental removal (Hint: use `limactl unprotect`)\")\n\t}\n\tif !force && inst.Status != limatype.StatusStopped {\n\t\treturn fmt.Errorf(\"expected status %#q, got %#q\", limatype.StatusStopped, inst.Status)\n\t}\n\n\tStopForcibly(inst)\n\n\tif len(inst.Errors) == 0 {\n\t\tif err := unregister(ctx, inst); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to unregister %#q: %w\", inst.Dir, err)\n\t\t}\n\t}\n\tif err := os.RemoveAll(inst.Dir); err != nil {\n\t\treturn fmt.Errorf(\"failed to remove %#q: %w\", inst.Dir, err)\n\t}\n\n\treturn nil\n}","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/instance/delete.go#L1-L37","documentation":"pkg/instance.Delete refuses to remove an instance whose Instance.Protected flag is set. The flag exists to prevent accidental deletion of important VMs (set via `limactl protect`). The error explicitly hints at the remedy: run `limactl unprotect` first.","triggerScenarios":"Calling instance.Delete(ctx, inst, force) (or `limactl delete`) on an instance whose lima.yaml instance dir contains the protection marker, regardless of the force argument.","commonSituations":"Scripted cleanup (CI or cron) that deletes all instances and encounters a VM the user protected; typing `limactl delete <name>` on a deliberately protected VM.","solutions":["Run `limactl unprotect <instance>` then retry the delete.","If programmatic, clear the protection marker per Lima's protected-instance mechanism before calling Delete.","Filter protected instances out of bulk-delete scripts using store.Inspect and checking inst.Protected."],"exampleFix":"// before\nlimactl delete myvm\n// after\nlimactl unprotect myvm && limactl delete myvm","handlingStrategy":"validation","validationCode":"inst, _ := store.Inspect(ctx, instName)\nif inst != nil && inst.Protected {\n    return fmt.Errorf(\"skip %s: protected\", instName)\n}","typeGuard":null,"tryCatchPattern":"if err := instance.Delete(ctx, inst, false); err != nil {\n    if strings.Contains(err.Error(), \"protected\") {\n        // require explicit unprotect before proceeding\n        return fmt.Errorf(\"run `limactl unprotect %s` first\", inst.Name)\n    }\n    return err\n}","preventionTips":["Check inst.Protected before bulk deletes","Only protect instances that matter, and document them","In CI, exclude protected instances from cleanup jobs"],"tags":["instance-delete","protected-instance","safety-guard"],"backgroundTag":"instance-protected","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}