sandboxlifecycle

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package sandboxlifecycle decides whether the Docker sandbox needs starting and, when it does, brings it up — reporting whether the caller now owns it. The ownership signal lets callers tear down only the sandbox they started.

Index

Constants

This section is empty.

Variables

View Source
var ErrExternalAccessDeclined = errors.New("external network access declined")

ErrExternalAccessDeclined is returned when the user answers no to the unrestricted-network-access prompt.

View Source
var ErrExternalAccessNeedsTTY = errors.New("allow_external = true requires interactive confirmation, but no TTY is available")

ErrExternalAccessNeedsTTY is returned when allow_external is true but no interactive terminal is available to confirm it. There is no bypass.

Functions

func ConfirmExternalAccess added in v0.11.4

func ConfirmExternalAccess(allowExternal, interactive bool, in io.Reader, out io.Writer) error

ConfirmExternalAccess gates unrestricted external network access behind a y/N prompt. When allowExternal is false it is a no-op. When true and interactive, it warns on out and reads the answer from in, returning nil only for "y"/"yes" and ErrExternalAccessDeclined otherwise. When true and not interactive, it returns ErrExternalAccessNeedsTTY.

func DefaultExternalAccessConfirm added in v0.11.4

func DefaultExternalAccessConfirm(cfg *config.Config) func() error

DefaultExternalAccessConfirm returns a confirm callback for Ensure that reads from stdin and warns on stderr, treating a terminal-attached stdin as interactive.

func Ensure

func Ensure(ctx context.Context, sb Sandbox, confirm func() error) (startedByUs bool, err error)

Ensure makes sb running. If it is already running, Ensure does nothing and reports startedByUs=false (the caller must not tear it down). If it was not running, Ensure invokes confirm (when non-nil) before calling Up; a non-nil error from confirm aborts startup. On success, Ensure brings sb up and reports startedByUs=true. Any failure is returned and startedByUs is false.

func NewExecutor

func NewExecutor(ctx context.Context, cfg *config.Config) (*container.ContainerExecutor, string, func(), error)

NewExecutor connects to Docker and builds a container executor for cfg's sandbox project (named deterministically from the current directory). The returned cleanup closes the Docker client and must be called by the caller.

Types

type Result

type Result struct {
	Executor    *container.ContainerExecutor
	ProjectName string
	StartedByUs bool
	// contains filtered or unexported fields
}

Result carries the outcome of EnsureUp: the executor to run/tear down the sandbox, its project name, and whether this call started it.

func EnsureUp

func EnsureUp(ctx context.Context, cfg *config.Config) (*Result, error)

EnsureUp builds the executor for cfg and ensures the sandbox is running. On any failure it closes the Docker client and returns the error; Claude must not be launched in that case.

func (*Result) Close

func (r *Result) Close()

Close releases the Docker client. Safe to call multiple times.

func (*Result) Down

func (r *Result) Down(ctx context.Context) error

Down stops and removes the sandbox.

func (*Result) Started

func (r *Result) Started() bool

Started reports whether this call started the sandbox (and therefore owns it).

type Sandbox

type Sandbox interface {
	IsRunning(context.Context) (bool, error)
	Up(context.Context) error
	Down(context.Context) error
}

Sandbox is the subset of the compose executor the lifecycle logic needs. *container.ContainerExecutor satisfies it.

Jump to

Keyboard shortcuts

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