# Images

> Choose the container image a function runs in: Python packages, shell commands, or your own base image.

Canonical page: https://klio.tech/docs/images

## Build an image

```python
from klio_compute import function, Image

image = Image(
    python_version="python3.12",
    python_packages=["transformers", "torch"],
    commands=["apt-get update && apt-get install -y ffmpeg"],
)

@function(image=image, gpu="L4")
def run():
    ...
```

Images are built once and reused. Klio Compute runs Python 3.12: `Image(python_version="python3.12")`, and plain `Image()`, is the supported image, and anything built on it can import `klio_compute` with nothing to install. Asking for another version stops with a message before anything is sent.

## Your own base image

```python
image = Image(base_image="docker.io/library/python:3.11-slim")
```

An image with its own `base_image` may use any Python. `Image` from `klio_compute` adds one build step that installs this release of `klio-compute` without its dependencies, so `from klio_compute import function` works inside it too. Set `KLIO_SDK_INSTALL_SPEC` to install it from somewhere else, such as a private mirror.

- Use `Image` from `klio_compute`, not from another package.
- Don't list `klio-compute` in `python_packages`: its dependencies would conflict with the versions the platform fixes in images.
- `klio run` and `klio deploy` also take `--dockerfile` to build from a Dockerfile.
