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 ¶
- type Cmd
- type ExecResult
- type Executor
- type KubernetesSandbox
- func (s *KubernetesSandbox) Close(ctx context.Context) error
- func (s *KubernetesSandbox) Command(name string, arg ...string) *Cmd
- func (s *KubernetesSandbox) CommandContext(ctx context.Context, name string, arg ...string) *Cmd
- func (s *KubernetesSandbox) Delete(ctx context.Context) error
- func (s *KubernetesSandbox) Execute(ctx context.Context, command string, env []string, workDir string) (*ExecResult, error)
- type Local
- type Option
- type Seatbelt
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 ¶
CombinedOutput runs the command and returns its combined standard output and standard error
func (*Cmd) Output ¶
Output runs the command and returns its standard output
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 ¶
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 ¶
Close is a no-op for Local executor.
type Option ¶
type Option func(*KubernetesSandbox) error
Option represents a configuration option for KubernetesSandbox
func WithKubeconfig ¶
WithKubeconfig sets the kubeconfig file path
func WithName ¶
WithName sets the sandbox name. Prefer passing the name via the constructor when possible.
Source Files
¶
- executor.go
- kubernetes.go
- local.go
- seatbelt_executor_others.go