Image | Daytona

Image

class Image(BaseModel)

Represents an image definition for a Daytona sandbox. Do not construct this class directly. Instead use one of its static factory methods, such as Image.base(), Image.debian_slim(), or Image.from_dockerfile().

Image.dockerfile

def dockerfile() -> str

Returns a generated Dockerfile for the image.

Image.pip_install

def pip_install(*packages: str | list[str],
                find_links: list[str] | None = None,
                index_url: str | None = None,
                extra_index_urls: list[str] | None = None,
                pre: bool = False,
                extra_options: str = "") -> "Image"

Adds commands to install packages using pip.

Arguments:

Returns:

Example:

image = Image.debian_slim("3.12").pip_install("requests", "pandas")

Image.pip_install_from_requirements

def pip_install_from_requirements(requirements_txt: str,
                                  find_links: list[str] | None = None,
                                  index_url: str | None = None,
                                  extra_index_urls: list[str] | None = None,
                                  pre: bool = False,
                                  extra_options: str = "") -> "Image"

Installs dependencies from a requirements.txt file.

Arguments:

Returns:

Example:

image = Image.debian_slim("3.12").pip_install_from_requirements("requirements.txt")

Image.pip_install_from_pyproject

def pip_install_from_pyproject(pyproject_toml: str,
                               optional_dependencies: list[str],
                               find_links: str | None = None,
                               index_url: str | None = None,
                               extra_index_url: str | None = None,
                               pre: bool = False,
                               extra_options: str = "") -> "Image"

Installs dependencies from a pyproject.toml file.

Arguments:

Returns:

Example:

image = Image.debian_slim("3.12")
                 .pip_install_from_pyproject("pyproject.toml", optional_dependencies=["dev"])

Image.add_local_file

def add_local_file(local_path: str | Path, remote_path: str) -> "Image"

Adds a local file to the image.

Arguments:

Returns:

Example:

image = Image.debian_slim("3.12").add_local_file("package.json", "/home/daytona/package.json")

Image.add_local_dir

def add_local_dir(local_path: str | Path, remote_path: str) -> "Image"

Adds a local directory to the image.

Arguments:

Returns:

Example:

image = Image.debian_slim("3.12").add_local_dir("src", "/home/daytona/src")

Image.run_commands

def run_commands(*commands: str | list[str]) -> "Image"

Runs commands in the image.

Arguments:

Returns:

Example:

image = Image.debian_slim("3.12").run_commands(
    'echo "Hello, world!"',
    ['bash', '-c', 'echo Hello, world, again!']
)

Image.env

def env(env_vars: dict[str, str]) -> "Image"

Sets environment variables in the image.

Arguments:

Returns:

Example:

image = Image.debian_slim("3.12").env({"PROJECT_ROOT": "/home/daytona"})

Image.workdir

def workdir(path: str | Path) -> "Image"

Sets the working directory in the image.

Arguments:

Returns:

Example:

image = Image.debian_slim("3.12").workdir("/home/daytona")

Image.entrypoint

def entrypoint(entrypoint_commands: list[str]) -> "Image"

Sets the entrypoint for the image.

Arguments:

Returns:

Example:

image = Image.debian_slim("3.12").entrypoint(["/bin/bash"])

Image.cmd

def cmd(cmd: list[str]) -> "Image"

Sets the default command for the image.

Arguments:

Returns:

Example:

image = Image.debian_slim("3.12").cmd(["/bin/bash"])

Image.dockerfile_commands

def dockerfile_commands(dockerfile_commands: list[str],
                        context_dir: Path | str | None = None,
                        *,
                        strict_context: bool = False) -> "Image"

Adds arbitrary Dockerfile-like commands to the image.

Arguments:

Returns:

Example:

image = Image.debian_slim("3.12").dockerfile_commands(["RUN echo 'Hello, world!'" ])

Image.from_dockerfile

@staticmethod
def from_dockerfile(path: str | Path,
                    *,
                    strict_context: bool = False) -> "Image"

Creates an Image from an existing Dockerfile.

Arguments:

Returns:

Example:

image = Image.from_dockerfile("Dockerfile")

Image.base

@staticmethod
def base(image: str) -> "Image"

Creates an Image from an existing base image.

Arguments:

Returns:

Example:

image = Image.base("python:3.12-slim-bookworm")

Context

class Context(BaseModel)

Context for an image.

Attributes: