Skip to content

Containers

Containers, like Docker, are a way to package software and its dependencies into a standardized unit for software development. Containers are lightweight, standalone, and executable software packages that include everything needed to run an application: code, runtime, system tools, system libraries, and settings.

Requirements

GenAIScript uses Docker to orchestrate the containers.

start a container

Start by creating and starting a new container. GenAIScript will pull the container image on demand and will remove the container when it is no longer needed.

const container = await host.container()

Custom image

By default, the container uses the python:alpine image, which provides a minimal python environment. You can change the image using the image option.

const container = await host.container({ image: "python:slim" })

Disable auto-purge

By default, the container is removed when it is no longer needed. You can disable this behavior using the disablePurge option.

const container = await host.container({ disablePurge: true })

Run a command

You can run a command in the container using the exec method. It returns the exit code, standard output and error streams.

const { stdout } = await container.exec("python", ["--version"])

Read and write files

The container has a volume mounted in the host file system, which allows to read and write files to the container.

await container.writeText("hello.txt", "Hello, world!")
const content = await container.readText("hello.txt")

Copy files to container

You can also copy files from the host to the container.

// src/* -> ./src/*
await container.copyTo("src/**", ".")

Using containers in tools

The containerized tools guide shows how to use containers in tools to handle untrusted text securely.