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 ¶
const ModeName = "docker_run"
ModeName is the identifier under which this backend registers with sandbox.RegisterFactory.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 ¶
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) Spawn ¶
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.