docker

package
v0.0.0-...-94a2dde Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package docker provides an explicitly constructed sandbox backed by a local Docker Engine. It uses the official Engine Go client and never pulls images.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	// contains filtered or unexported fields
}

Backend owns one Docker container and its mounted workspace. File operations are confined to the workspace; Execute runs inside the container.

func New

func New(ctx context.Context, image string, options Options) (*Backend, error)

New connects to Docker using the standard environment variables and API version negotiation, then creates and starts one owned container. Closing the backend also closes the Engine client created by this function.

func NewWithClient

func NewWithClient(ctx context.Context, client *engineclient.Client, image string, options Options) (*Backend, error)

NewWithClient creates an owned container using a caller-managed Engine client. Closing the backend removes the container but does not close client.

func (*Backend) Close

func (backend *Backend) Close() error

Close removes the container using a bounded background context.

func (*Backend) Delete

func (backend *Backend) Delete(ctx context.Context, name string) (dabackend.DeleteResult, error)

func (*Backend) Download

func (backend *Backend) Download(ctx context.Context, paths []string) []dabackend.DownloadResult

func (*Backend) Edit

func (backend *Backend) Edit(ctx context.Context, name, old, replacement string, replaceAll bool) (dabackend.EditResult, error)

func (*Backend) Execute

func (backend *Backend) Execute(ctx context.Context, command string, timeout time.Duration) (dabackend.ExecuteResult, error)

func (*Backend) ExecuteWithOptions

func (backend *Backend) ExecuteWithOptions(ctx context.Context, command string, options dabackend.ExecuteOptions) (dabackend.ExecuteResult, error)

func (*Backend) Glob

func (backend *Backend) Glob(ctx context.Context, pattern, base string) (dabackend.GlobResult, error)

func (*Backend) Grep

func (backend *Backend) Grep(ctx context.Context, pattern string, options dabackend.GrepOptions) (dabackend.GrepResult, error)

func (*Backend) ID

func (backend *Backend) ID() string

func (*Backend) List

func (backend *Backend) List(ctx context.Context, directory string) (dabackend.ListResult, error)

func (*Backend) Read

func (backend *Backend) Read(ctx context.Context, name string, offset, limit int) (dabackend.ReadResult, error)

func (*Backend) ReadBinary

func (backend *Backend) ReadBinary(ctx context.Context, name string, maxBytes int64) (dabackend.ReadResult, error)

func (*Backend) Shutdown

func (backend *Backend) Shutdown(ctx context.Context) error

Shutdown removes the owned container and, when the backend created it, its temporary workspace. A failed container removal leaves the workspace intact.

func (*Backend) Upload

func (backend *Backend) Upload(ctx context.Context, uploads []dabackend.Upload) []dabackend.UploadResult

func (*Backend) Workspace

func (backend *Backend) Workspace() string

Workspace returns the host directory mounted as the sandbox workspace.

func (*Backend) Write

func (backend *Backend) Write(ctx context.Context, name, content string) (dabackend.WriteResult, error)

type Options

type Options struct {
	// Name optionally assigns a container name. Docker generates one otherwise.
	Name string
	// Workspace optionally supplies the host directory mounted at Workdir. When
	// omitted, the backend creates a private temporary directory removed by Close.
	Workspace string
	// Workdir defaults to /workspace.
	Workdir string
	// User defaults to the current numeric uid:gid on Unix. Set it explicitly
	// when the image requires a different identity.
	User string
	// Env adds container environment variables. HOME defaults to Workdir unless
	// Env supplies it.
	Env map[string]string
	// Network defaults to none. Set it explicitly to grant network access.
	Network string
	// WritableRoot opts out of the read-only container root filesystem. The
	// workspace and /tmp remain writable either way.
	WritableRoot bool
	// Resource limits use secure non-zero defaults. Negative values are invalid.
	// A zero value selects the documented default rather than disabling a limit.
	MemoryBytes int64
	CPUs        float64
	PidsLimit   int64

	DefaultTimeout time.Duration
	MaxOutput      int
	MaxFileSize    int64
	MaxVideoSize   int64
	MaxResults     int
}

Options controls a Docker sandbox created and owned by New or NewWithClient.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL