dockerrun

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package dockerrun is an example sandbox implementation that runs each exec-hook invocation in a fresh disposable container via `docker run --rm -i`. The hook subprocess still sees the standard stdin/stdout JSON protocol; only the spawn mechanism changes.

This is reference/example code — not imported by PromptKit core. Copy, adapt, or import the package directly; either path is fine. Register the factory in your own init or via sdk.WithSandboxFactory:

import (
    "github.com/AltairaLabs/PromptKit/runtime/hooks/sandbox"
    "github.com/AltairaLabs/PromptKit/sdk/examples/sandboxes/dockerrun"
)

func init() {
    _ = sandbox.RegisterFactory(dockerrun.ModeName, dockerrun.Factory)
}

Or programmatically, without the registry:

sb := dockerrun.New(dockerrun.Config{Image: "python:3.12-slim"})
hook := hooks.NewExecProviderHook(&hooks.ExecHookConfig{
    Command: "/hooks/pii.py",
    Sandbox: sb,
    ...
})

Configuration (via the Factory config map):

mode: docker_run
image: python:3.12-slim       # required
network: none                 # optional; maps to --network=<value>
mounts:                       # optional; each value is passed as -v <spec>
  - ./hooks:/hooks:ro
extra_args:                   # optional; arbitrary extra docker flags
  - --memory=256m
  - --cpus=0.5

Index

Constants

View Source
const ModeName = "docker_run"

ModeName is the identifier under which this backend registers with sandbox.RegisterFactory.

Variables

This section is empty.

Functions

func Factory

func Factory(name string, cfg map[string]any) (sandbox.Sandbox, error)

Factory is a sandbox.Factory compatible with RuntimeConfig-based resolution. It reads the config map, validates required fields, and returns a ready Sandbox.

Types

type Config

type Config struct {
	// Image is the container image to run. Required.
	Image string
	// Network maps to `docker run --network=<value>`. Empty means
	// don't pass the flag (docker default).
	Network string
	// Mounts are passed as `-v <spec>` for each entry. Example:
	// "./hooks:/hooks:ro" bind-mounts the hooks directory read-only.
	Mounts []string
	// ExtraArgs are extra `docker run` arguments inserted after the
	// standard flags and before the image. Use sparingly.
	ExtraArgs []string
	// DockerPath overrides the `docker` binary name. Empty uses `docker`
	// resolved from PATH.
	DockerPath string
}

Config configures the docker-run backend.

type Sandbox

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

Sandbox runs exec-hook commands inside a fresh docker container per call.

func New

func New(cfg Config) *Sandbox

New constructs a Sandbox from a Config. The inner direct backend handles the actual subprocess spawning, timeout, and stdin piping; we just rewrite argv to prepend `docker run`.

func NewNamed

func NewNamed(name string, cfg Config) *Sandbox

NewNamed is like New but lets the caller override the sandbox name (useful when multiple docker-run sandboxes are registered under different names in RuntimeConfig).

func (*Sandbox) Name

func (s *Sandbox) Name() string

Name returns the sandbox's name.

func (*Sandbox) Spawn

func (s *Sandbox) Spawn(ctx context.Context, req sandbox.Request) (sandbox.Response, error)

Spawn builds a `docker run --rm -i [flags] <image> <cmd> <args...>` argv and delegates to the inner direct sandbox, which handles stdin piping, timeout, and stdout/stderr collection. The hook subprocess inside the container receives req.Stdin on its stdin exactly as it would with the direct backend.

Jump to

Keyboard shortcuts

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