lima-vm/lima · error

instance is protected to prohibit accidental removal (Hint:

Error message

instance is protected to prohibit accidental removal (Hint: use `limactl unprotect`)

What it means

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.

Source

Thrown at pkg/instance/delete.go:19

// SPDX-FileCopyrightText: Copyright The Lima Authors
// SPDX-License-Identifier: Apache-2.0

package instance

import (
	"context"
	"errors"
	"fmt"
	"os"

	"github.com/lima-vm/lima/v2/pkg/driver/external/server"
	"github.com/lima-vm/lima/v2/pkg/driverutil"
	"github.com/lima-vm/lima/v2/pkg/limatype"
)

func Delete(ctx context.Context, inst *limatype.Instance, force bool) error {
	if inst.Protected {
		return errors.New("instance is protected to prohibit accidental removal (Hint: use `limactl unprotect`)")
	}
	if !force && inst.Status != limatype.StatusStopped {
		return fmt.Errorf("expected status %#q, got %#q", limatype.StatusStopped, inst.Status)
	}

	StopForcibly(inst)

	if len(inst.Errors) == 0 {
		if err := unregister(ctx, inst); err != nil {
			return fmt.Errorf("failed to unregister %#q: %w", inst.Dir, err)
		}
	}
	if err := os.RemoveAll(inst.Dir); err != nil {
		return fmt.Errorf("failed to remove %#q: %w", inst.Dir, err)
	}

	return nil
}

View on GitHub (pinned to dd909d0973)

Solutions

  1. Run `limactl unprotect <instance>` then retry the delete.
  2. If programmatic, clear the protection marker per Lima's protected-instance mechanism before calling Delete.
  3. Filter protected instances out of bulk-delete scripts using store.Inspect and checking inst.Protected.

Example fix

// before
limactl delete myvm
// after
limactl unprotect myvm && limactl delete myvm
Defensive patterns

Strategy: validation

Validate before calling

inst, _ := store.Inspect(ctx, instName)
if inst != nil && inst.Protected {
    return fmt.Errorf("skip %s: protected", instName)
}

Try / catch

if err := instance.Delete(ctx, inst, false); err != nil {
    if strings.Contains(err.Error(), "protected") {
        // require explicit unprotect before proceeding
        return fmt.Errorf("run `limactl unprotect %s` first", inst.Name)
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01). Data as JSON: /api/errors/7496af6e65cd8079. Report an issue: GitHub.