sandbox

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package sandbox provides Kubernetes-based sandboxed command execution with an exec.Command-like interface A sandbox represents an isolated execution environment. Currently implemented using Kubernetes pods, but can be extended to support other backends like Docker containers in the future.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd struct {

	// Standard streams (similar to exec.Cmd)
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
	// contains filtered or unexported fields
}

Cmd represents a command to be executed in a sandbox It follows the same interface pattern as exec.Cmd

func (*Cmd) CombinedOutput

func (c *Cmd) CombinedOutput() ([]byte, error)

CombinedOutput runs the command and returns its combined standard output and standard error

func (*Cmd) Output

func (c *Cmd) Output() ([]byte, error)

Output runs the command and returns its standard output

func (*Cmd) Run

func (c *Cmd) Run() error

Run executes the command and waits for it to complete

type ExecResult

type ExecResult struct {
	Command    string `json:"command,omitempty"`
	Error      string `json:"error,omitempty"`
	Stdout     string `json:"stdout,omitempty"`
	Stderr     string `json:"stderr,omitempty"`
	ExitCode   int    `json:"exit_code,omitempty"`
	StreamType string `json:"stream_type,omitempty"`
}

ExecResult represents the result of a command execution.

func (*ExecResult) String

func (e *ExecResult) String() string

type Executor

type Executor interface {
	// Execute runs a command and returns the result.
	Execute(ctx context.Context, command string, env []string, workDir string) (*ExecResult, error)

	// Close cleans up any resources associated with the executor.
	Close(ctx context.Context) error
}

Executor defines the interface for executing commands.

type KubernetesSandbox

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

KubernetesSandbox represents a Kubernetes-based sandboxed execution environment

func NewKubernetesSandbox

func NewKubernetesSandbox(name string, opts ...Option) (*KubernetesSandbox, error)

NewKubernetesSandbox creates a new KubernetesSandbox instance with the given name and options

func (*KubernetesSandbox) Close

func (s *KubernetesSandbox) Close(ctx context.Context) error

Close cleans up the sandbox resources.

func (*KubernetesSandbox) Command

func (s *KubernetesSandbox) Command(name string, arg ...string) *Cmd

Command creates a new Cmd to execute the given command in the sandbox This follows the same interface as exec.Command

func (*KubernetesSandbox) CommandContext

func (s *KubernetesSandbox) CommandContext(ctx context.Context, name string, arg ...string) *Cmd

CommandContext creates a new Cmd with a context

func (*KubernetesSandbox) Delete

func (s *KubernetesSandbox) Delete(ctx context.Context) error

Delete removes the sandbox pod and its associated resources, waiting for them to be fully terminated. It does not return an error if the resources are already deleted.

func (*KubernetesSandbox) Execute

func (s *KubernetesSandbox) Execute(ctx context.Context, command string, env []string, workDir string) (*ExecResult, error)

Execute executes the command in the sandbox.

type Local

type Local struct{}

Local executes commands locally.

func NewLocalExecutor

func NewLocalExecutor() *Local

NewLocalExecutor creates a new LocalExecutor.

func (*Local) Close

func (e *Local) Close(ctx context.Context) error

Close is a no-op for Local executor.

func (*Local) Execute

func (e *Local) Execute(ctx context.Context, command string, env []string, workDir string) (*ExecResult, error)

Execute executes the command locally.

type Option

type Option func(*KubernetesSandbox) error

Option represents a configuration option for KubernetesSandbox

func WithImage

func WithImage(image string) Option

WithImage sets the container image

func WithKubeconfig

func WithKubeconfig(kubeconfig string) Option

WithKubeconfig sets the kubeconfig file path

func WithName

func WithName(name string) Option

WithName sets the sandbox name. Prefer passing the name via the constructor when possible.

func WithNamespace

func WithNamespace(namespace string) Option

WithNamespace sets the namespace

type Seatbelt

type Seatbelt struct{}

Seatbelt executes commands in a seatbelt sandbox.

func NewSeatbeltExecutor

func NewSeatbeltExecutor() *Seatbelt

NewSeatbeltExecutor creates a new SeatbeltExecutor.

func (*Seatbelt) Close

func (e *Seatbelt) Close(ctx context.Context) error

Close is a no-op for Seatbelt executor.

func (*Seatbelt) Execute

func (e *Seatbelt) Execute(ctx context.Context, command string, env []string, workDir string) (*ExecResult, error)

Execute executes the command in the seatbelt sandbox.

Source Files

  • executor.go
  • kubernetes.go
  • local.go
  • seatbelt_executor_others.go

Jump to

Keyboard shortcuts

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