# Autokill

Autokill automatically deletes instances, service groups, templates, and checkpoints when a configured condition triggers.
It stops workloads from piling up after they finish and are no longer needed.

You can configure autokill on:
- [**Instances**](/platform/instances): killed after a time, or after reaching a request limit.
- [**Instance templates**](/platform/instances#instance-templates): killed if nobody clones them within a specified time.
- [**Service groups**](/platform/services): killed after the group has been empty for a specified time.
- [**Checkpoints**](/features/checkpoints): killed if nobody restores them within a specified time.

Set autokill with the `--autokill` flag on the `create` and `edit` commands of each resource.

## Instance autokill

:::caution
Autokill skips any instance that has a [delete lock](/platform/delete-locks) set.
The autokill timer doesn't fire while a delete lock is active.
:::

### Kill after stopped duration

Automatically kill an instance after it stops and remains stopped for a given time:

```bash
unikraft instance create --metro fra \
  --autokill time=1h ...
```

This example kills the instance 1 hour after it stops.

### Kill after a request count

Kill an instance after it serves a specified request count:

```bash
unikraft instance create --metro fra \
  --autokill num-requests=1000 ...
```

### Updating autokill on a stopped instance

```bash
unikraft instance edit <instance-name> --autokill time=10s
```

The new value replaces the whole policy.
To keep a request limit, pass it again, for example `--autokill time=10s,num-requests=1000`.

## Service group autokill

Automatically kill a service group after it stays empty (no instances) for a given time:

```bash
unikraft service create --metro fra \
  --autokill time=5m ...
```

This example kills the service group 5 minutes after its last instance leaves.

## Instance template autokill

:::info
When you clone an instance from a template, the new instance inherits the autokill configuration.
:::

Automatically kill an instance template if nobody clones it within a given time:

```bash
unikraft instance template create my-instance \
  --autokill time=24h
```

This example converts the existing instance `my-instance` into a template, in that instance's metro, and removes the template after 24 hours without a clone.

## Checkpoint autokill

Automatically kill a [checkpoint](/features/checkpoints) if nobody restores it within a given time:

```bash
unikraft instance checkpoint create my-instance \
  --autokill time=1h
```

This example removes the checkpoint after 1 hour without a restore.

## Changing autokill

Use the `edit` command of the resource to set or change its autokill policy:

```bash
unikraft service edit <service-name> --autokill time=10m
unikraft instance template edit <template-name> --autokill time=48h
unikraft instance checkpoint edit <checkpoint-name> --autokill time=2h
```

## Listing and filtering

The `autokill.time` and `autokill.num-requests` fields work like any other field.
You can list, filter, sort, and inspect them:

```bash
unikraft instance list --filter 'autokill.time>0s' --sort autokill.time
```

## Learn more

* Unikraft Cloud's [REST API reference](/api/platform/v1), in particular the sections on [instances](/api/platform/v1/instances) and [services](/api/platform/v1/servicegroups).
