sandbox

package
v0.0.0-...-360ba47 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: GPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckDockerAvailability

func CheckDockerAvailability() error

CheckDockerAvailability verifies Docker is installed and accessible

func EnsureIOContainerImage

func EnsureIOContainerImage(imageName string) error

EnsureIOContainerImage verifies the I/O container image exists

func ExecuteInPooledContainer

func ExecuteInPooledContainer(ctx context.Context, pool *ContainerPool, command string, repoRoot string) (string, error)

ExecuteInPooledContainer executes a command using a container from the pool

func PullDockerImage

func PullDockerImage(image string) error

PullDockerImage ensures the required image is available

func ReadFileInContainer

func ReadFileInContainer(filePath, repoRoot, containerImage string, timeout time.Duration, memLimit string, cpuLimit int) (string, error)

ReadFileInContainer reads a file using the I/O container

func ReadFileInContainerPooled

func ReadFileInContainerPooled(ctx context.Context, pool *ContainerPool, filePath, repoRoot string) (string, error)

ReadFileInContainerPooled reads a file using a pooled container

func RunIOContainer

func RunIOContainer(repoRoot, containerImage, command string, timeout time.Duration, memLimit string, cpuLimit int) (string, error)

RunIOContainer executes a containerized I/O operation

func ValidateContainerImageName

func ValidateContainerImageName(image string) error

ValidateContainerImageName ensures the image name is well-formed and free of shell metacharacters

func ValidateExecCommand

func ValidateExecCommand(command string, whitelist []string) error

ValidateExecCommand checks if the command is allowed to execute Note: Exec is always enabled in container-only mode

func ValidateIOContainer

func ValidateIOContainer(repoRoot, containerImage string) error

ValidateIOContainer runs pre-flight checks for containerized I/O

func ValidatePath

func ValidatePath(requestedPath string, repositoryRoot string, excludedPaths []string) (string, error)

func ValidateWriteExtension

func ValidateWriteExtension(filePath string, allowedExtensions []string) error

ValidateWriteExtension checks if the file extension is allowed for writing

func WriteFileInContainer

func WriteFileInContainer(filePath, content, repoRoot, containerImage string, timeout time.Duration, memLimit string, cpuLimit int) error

WriteFileInContainer writes a file using the I/O container

func WriteFileInContainerPooled

func WriteFileInContainerPooled(ctx context.Context, pool *ContainerPool, filePath, content, repoRoot string) error

WriteFileInContainerPooled writes a file using a pooled container

Types

type AuditLogger

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

AuditLogger handles audit logging operations

func NewAuditLogger

func NewAuditLogger(logPath string) (*AuditLogger, error)

NewAuditLogger creates a new audit logger

func (*AuditLogger) Close

func (a *AuditLogger) Close() error

Close closes the audit log file

func (*AuditLogger) Log

func (a *AuditLogger) Log(sessionID, command, argument string, success bool, errorMsg string)

Log writes an audit log entry

type ContainerConfig

type ContainerConfig struct {
	Image       string
	Command     string
	RepoRoot    string
	MemoryLimit string
	CPULimit    int
	Timeout     time.Duration
	Stdin       string // NEW: stdin content to pass to container
}

ContainerConfig holds configuration for running a container

type ContainerPool

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

ContainerPool manages a pool of reusable Docker containers

func NewContainerPool

func NewContainerPool(ctx context.Context, cfg PoolConfig) (*ContainerPool, error)

NewContainerPool creates a new container pool

func (*ContainerPool) Close

func (p *ContainerPool) Close() error

Close shuts down the pool and cleans up all containers

func (*ContainerPool) Get

Get acquires a container from the pool

func (*ContainerPool) Return

func (p *ContainerPool) Return(ctx context.Context, container *PooledContainer) error

Return releases a container back to the pool

func (*ContainerPool) Stats

func (p *ContainerPool) Stats() map[string]interface{}

Stats returns pool statistics

type ContainerResult

type ContainerResult struct {
	ExitCode int
	Stdout   string
	Stderr   string
	Duration time.Duration
}

ContainerResult holds the result of container execution

func RunContainer

func RunContainer(cfg ContainerConfig) (ContainerResult, error)

RunContainer executes a command in a Docker container with security restrictions

type PoolConfig

type PoolConfig struct {
	Size                int
	MaxUsesPerContainer int
	IdleTimeout         time.Duration
	HealthCheckInterval time.Duration
	StartupContainers   int
	Image               string
	MemoryLimit         string
	CPULimit            int
	RepoRoot            string
}

PoolConfig holds pool configuration

type PooledContainer

type PooledContainer struct {
	ID         string
	Image      string
	UsageCount int
	MaxUses    int
	CreatedAt  time.Time
	LastUsedAt time.Time
	InUse      bool
	Healthy    bool
	// contains filtered or unexported fields
}

PooledContainer represents a container in the pool

Jump to

Keyboard shortcuts

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