{"modulePath":"github.com/GoCodeAlone/workflow","version":"v0.87.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package sandbox\n\nPackage sandbox provides Docker-based sandboxed execution for CI/CD pipeline steps.\n\n## Constants\n\n```go\nconst (\n\tRecordMaxMemoryBytes = 1 \u003c\u003c 30\n\tRecordMaxCPUs        = 2\n\tRecordMaxPIDs        = 256\n\tRecordMaxTimeout     = 10 * time.Minute\n)\n```\n\n```go\nconst MaxOutputBytes = 1 \u003c\u003c 20\n```\n\n## Functions\n\n```go\nfunc ValidateFilesystem(cfg SandboxConfig) error\n```\nValidateFilesystem validates the step's literal container-only writable paths.\n\n```go\nfunc ValidateRecordConfig(cfg SandboxConfig) error\n```\nValidateRecordConfig is the parent-side policy for brokered local execution. Errors deliberately never include config values, environment, or credentials.\n\n```go\nfunc WithLocalRunnerFactory(ctx context.Context, factory func(SandboxConfig) (SandboxRunner, error)) context.Context\n```\nWithLocalRunnerFactory binds host-owned local execution, including record-mode broker custody, without changing named remote/provider runner behavior.\n\n## Types\n\n```go\ntype DockerSandbox struct {\n\t// contains filtered or unexported fields\n}\n```\nDockerSandbox wraps the Docker CLI to execute commands in isolated containers.\n\n```go\nfunc NewDockerSandbox(config SandboxConfig) (*DockerSandbox, error)\n```\nNewDockerSandbox creates a new DockerSandbox with the given configuration. It requires the Docker CLI to be present on PATH.\n\n```go\nfunc (s *DockerSandbox) Close() error\n```\nClose cleans up resources held by the sandbox.\n\n```go\nfunc (s *DockerSandbox) CopyIn(ctx context.Context, srcPath, destPath string) error\n```\nCopyIn copies a file from the host into the active container. Call CreateContainer first to set the active container ID.\n\n```go\nfunc (s *DockerSandbox) CopyOut(ctx context.Context, srcPath string) (io.ReadCloser, error)\n```\nCopyOut copies a file out of the active container. Returns a ReadCloser with a tar archive containing the file contents, matching Docker copy semantics. Call CreateContainer first to set the active container ID.\n\n```go\nfunc (s *DockerSandbox) CreateContainer(ctx context.Context, cmd []string) error\n```\nCreateContainer creates a container, storing its ID for use with CopyIn/CopyOut. Call RemoveContainer when done to clean up.\n\n```go\nfunc (s *DockerSandbox) Exec(ctx context.Context, cmd []string) (*ExecResult, error)\n```\nExec creates a container, runs the given command, captures output, and removes the container.\n\n```go\nfunc (s *DockerSandbox) ExecInContainer(ctx context.Context, cmd []string, copyIn map[string]string, copyOutPaths []string) (*ExecResult, map[string]io.ReadCloser, error)\n```\nExecInContainer creates a container, copies files in, runs the command, and allows file extraction. This is the higher-level API that manages the full container lifecycle with file I/O.\n\n```go\nfunc (s *DockerSandbox) RemoveContainer(ctx context.Context) error\n```\nRemoveContainer stops and removes the active container.\n\n```go\ntype ExecResult struct {\n\tExitCode int\n\tStdout   string\n\tStderr   string\n}\n```\nExecResult holds the output from a command execution inside the sandbox.\n\n```go\ntype Mount struct {\n\tSource   string `yaml:\"source\"`\n\tTarget   string `yaml:\"target\"`\n\tReadOnly bool   `yaml:\"read_only\"`\n}\n```\nMount describes a bind mount from host to container.\n\n```go\ntype SandboxConfig struct {\n\t// Profile is the security profile name that produced this config (\"strict\",\n\t// \"standard\", \"permissive\"). It is informational - it does not affect local\n\t// Docker execution but is forwarded to remote runners so they can apply their\n\t// own profile clamping (ADR 0019).\n\tProfile     string            `yaml:\"profile,omitempty\"`\n\tImage       string            `yaml:\"image\"`\n\tWorkDir     string            `yaml:\"work_dir\"`\n\tEnv         map[string]string `yaml:\"env\"`\n\tMounts      []Mount           `yaml:\"mounts\"`\n\tMemoryLimit int64             `yaml:\"memory_limit\"`\n\tCPULimit    float64           `yaml:\"cpu_limit\"`\n\tTimeout     time.Duration     `yaml:\"timeout\"`\n\tNetworkMode string            `yaml:\"network_mode\"`\n\n\t// Security hardening fields\n\tSecurityOpts    []string          `yaml:\"security_opts\"` // e.g., [\"seccomp=default.json\"]\n\tCapAdd          []string          `yaml:\"cap_add\"`       // capabilities to add\n\tCapDrop         []string          `yaml:\"cap_drop\"`      // e.g., [\"ALL\"]\n\tReadOnlyRootfs  bool              `yaml:\"read_only_rootfs\"`\n\tNoNewPrivileges bool              `yaml:\"no_new_privileges\"`\n\tUser            string            `yaml:\"user\"`       // e.g., \"nobody:nogroup\"\n\tPidsLimit       int64             `yaml:\"pids_limit\"` // max process count\n\tTmpfs           map[string]string `yaml:\"tmpfs\"`      // e.g., {\"/tmp\": \"size=64m,noexec\"}\n}\n```\nSandboxConfig holds configuration for a Docker sandbox execution environment.\n\n```go\nfunc BuildSandboxConfig(profile, image string) SandboxConfig\n```\nBuildSandboxConfig maps a named security profile and image to a SandboxConfig. This is the single shared profile-→-config mapping used by step.sandbox\\_exec and reused by remote runner implementations (PR7/8) for their profile clamping.\n\nProfiles:\n\n  - \"strict\"     — hardened defaults via DefaultSecureSandboxConfig (no network, drop ALL caps, read-only rootfs).\n  - \"standard\"   — drops a curated set of dangerous capabilities, bridges network.\n  - \"permissive\" — minimal restrictions, bridges network.\n\nUnknown profiles default to \"strict\" (same behaviour as the step's original switch).\n\n```go\nfunc DefaultSecureSandboxConfig(image string) SandboxConfig\n```\nDefaultSecureSandboxConfig returns a hardened SandboxConfig suitable for running untrusted workloads. It uses a minimal Wolfi-based image, drops all Linux capabilities, enables a read-only root filesystem, mounts /tmp as tmpfs with noexec, and disables network access.\n\n```go\nfunc (c SandboxConfig) GetProfile() string\n```\nGetProfile returns the profile name stored in the config, falling back to \"strict\" (the safest default) when the field is empty.\n\n```go\ntype SandboxRunner interface {\n\t// Exec runs cmd inside the sandbox and returns the combined result.\n\tExec(ctx context.Context, cmd []string) (*ExecResult, error)\n\t// Close releases any resources held by the runner (e.g. Docker client).\n\tClose() error\n}\n```\nSandboxRunner is the interface consumed by step.sandbox\\_exec. Only Exec and Close are required — all other DockerSandbox methods are lifecycle helpers not used by the step's Execute path.\n\n```go\nfunc NewLocalDockerRunner(cfg SandboxConfig) (SandboxRunner, error)\n```\nNewLocalDockerRunner creates a SandboxRunner backed by a local Docker daemon. It is the default runner used when exec\\_env is absent or set to \"local-docker\".\n\n```go\nfunc NewLocalRunner(ctx context.Context, cfg SandboxConfig) (SandboxRunner, error)\n```\nNewLocalRunner uses the context's host runner, falling back to local Docker.\n\n","path":"github.com/GoCodeAlone/workflow/sandbox","name":"sandbox","synopsis":"Package sandbox provides Docker-based sandboxed execution for CI/CD pipeline steps.","isRedistributable":true}
