types

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package types defines error types for the sandbox service.

Package types defines the core domain types for the sandbox service.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSandboxNotFound  = errors.New("sandbox not found")
	ErrCodebaseNotFound = errors.New("codebase not found")
	ErrSessionNotFound  = errors.New("session not found")
	ErrSessionClosed    = errors.New("session is closed")
	ErrInvalidStatus    = errors.New("invalid sandbox status for this operation")
	ErrAlreadyRunning   = errors.New("sandbox is already running")
	ErrNotRunning       = errors.New("sandbox is not running")
	ErrPermissionDenied = errors.New("permission denied")
	ErrNotVisible       = errors.New("file or directory not visible")
	ErrInvalidPattern   = errors.New("invalid permission pattern")
	ErrTimeout          = errors.New("operation timed out")
)

Common errors

Functions

This section is empty.

Types

type Codebase

type Codebase struct {
	ID        string    `json:"id"`
	Name      string    `json:"name"`
	Path      string    `json:"-"` // Internal storage path (not exposed)
	OwnerID   string    `json:"owner_id"`
	Size      int64     `json:"size"`
	FileCount int       `json:"file_count"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Codebase represents a user's file folder that can be mounted into sandboxes.

type CreateCodebaseRequest

type CreateCodebaseRequest struct {
	Name    string `json:"name"`
	OwnerID string `json:"owner_id"`
}

CreateCodebaseRequest represents a request to create a new codebase.

type CreateSandboxRequest

type CreateSandboxRequest struct {
	CodebaseID  string            `json:"codebase_id"`
	Permissions []PermissionRule  `json:"permissions"`
	ExpiresIn   *time.Duration    `json:"expires_in,omitempty"`
	Labels      map[string]string `json:"labels,omitempty"`
	// Runtime configuration
	Runtime   RuntimeType     `json:"runtime,omitempty"`   // Runtime type: bwrap, docker
	Resources *ResourceLimits `json:"resources,omitempty"` // Resource limits
	Docker    *DockerConfig   `json:"docker,omitempty"`    // Docker-specific config
}

CreateSandboxRequest represents a request to create a new sandbox.

type CreateSessionRequest

type CreateSessionRequest struct {
	SandboxID string            `json:"sandbox_id"`
	Shell     string            `json:"shell,omitempty"`
	Env       map[string]string `json:"env,omitempty"`
}

CreateSessionRequest represents a request to create a new session.

type DockerConfig

type DockerConfig struct {
	Image      string            `json:"image,omitempty"`      // Docker image (e.g., "python:3.11-slim")
	Network    string            `json:"network,omitempty"`    // Network mode: "none", "bridge", "host"
	Privileged bool              `json:"privileged,omitempty"` // Run in privileged mode (not recommended)
	Env        map[string]string `json:"env,omitempty"`        // Additional environment variables
}

DockerConfig holds Docker-specific sandbox configuration.

type ExecError

type ExecError struct {
	SandboxID string
	Command   string
	ExitCode  int
	Stderr    string
}

ExecError represents a command execution error.

func (*ExecError) Error

func (e *ExecError) Error() string

type ExecRecord

type ExecRecord struct {
	ID         string        `json:"id"`
	SandboxID  string        `json:"sandbox_id"`
	Command    string        `json:"command"`
	Stdin      string        `json:"stdin,omitempty"`
	Stdout     string        `json:"stdout"`
	Stderr     string        `json:"stderr"`
	ExitCode   int           `json:"exit_code"`
	StartedAt  time.Time     `json:"started_at"`
	FinishedAt time.Time     `json:"finished_at"`
	Duration   time.Duration `json:"duration"`
}

ExecRecord represents a historical record of command execution.

type ExecRequest

type ExecRequest struct {
	Command string            `json:"command"`
	Stdin   string            `json:"stdin,omitempty"`
	Env     map[string]string `json:"env,omitempty"`
	WorkDir string            `json:"workdir,omitempty"`
	Timeout time.Duration     `json:"timeout,omitempty"`
}

ExecRequest represents a command execution request.

type ExecResult

type ExecResult struct {
	Stdout   string        `json:"stdout"`
	Stderr   string        `json:"stderr"`
	ExitCode int           `json:"exit_code"`
	Duration time.Duration `json:"duration"`
}

ExecResult represents the result of a command execution.

type PatternType

type PatternType string

PatternType indicates how a permission pattern should be matched.

const (
	PatternGlob      PatternType = "glob"      // e.g., *.md, **/*.json
	PatternDirectory PatternType = "directory" // e.g., /docs/
	PatternFile      PatternType = "file"      // e.g., /config.yaml (highest priority)
)

type Permission

type Permission string

Permission represents the access level for a file or directory.

const (
	PermNone  Permission = "none"  // Completely invisible, not shown in ls
	PermView  Permission = "view"  // Can see filename in ls, but cannot read content
	PermRead  Permission = "read"  // Can view and read content
	PermWrite Permission = "write" // Can modify file
)

func (Permission) Level

func (p Permission) Level() int

PermissionLevel returns the numeric level of a permission for comparison. Higher level means more permissive.

type PermissionError

type PermissionError struct {
	Path       string
	Operation  string
	Permission Permission
	Required   Permission
}

PermissionError represents a file permission error with context.

func (*PermissionError) Error

func (e *PermissionError) Error() string

type PermissionRule

type PermissionRule struct {
	Pattern    string      `json:"pattern"`    // Path pattern: "/docs/**", "*.md", "/config.yaml"
	Type       PatternType `json:"type"`       // Pattern type: glob/directory/file
	Permission Permission  `json:"permission"` // Access level: none/view/read/write
	Priority   int         `json:"priority"`   // Higher priority rules override lower ones
}

PermissionRule defines a permission rule for file access.

type ResourceLimits

type ResourceLimits struct {
	Memory    int64 `json:"memory,omitempty"`     // Memory limit in bytes (e.g., 512*1024*1024 for 512MB)
	CPUQuota  int64 `json:"cpu_quota,omitempty"`  // CPU quota in microseconds per 100ms period
	CPUShares int64 `json:"cpu_shares,omitempty"` // CPU shares (relative weight)
	PidsLimit int64 `json:"pids_limit,omitempty"` // Maximum number of processes
}

ResourceLimits defines resource constraints for a sandbox.

type RuntimeType

type RuntimeType string

RuntimeType specifies the sandbox runtime implementation.

const (
	RuntimeUnspecified RuntimeType = ""
	RuntimeBwrap       RuntimeType = "bwrap"
	RuntimeDocker      RuntimeType = "docker"
)

type Sandbox

type Sandbox struct {
	ID          string            `json:"id"`
	CodebaseID  string            `json:"codebase_id"`
	Permissions []PermissionRule  `json:"permissions"`
	Status      SandboxStatus     `json:"status"`
	Labels      map[string]string `json:"labels,omitempty"`
	CreatedAt   time.Time         `json:"created_at"`
	StartedAt   *time.Time        `json:"started_at,omitempty"`
	StoppedAt   *time.Time        `json:"stopped_at,omitempty"`
	ExpiresAt   *time.Time        `json:"expires_at,omitempty"`

	// Runtime configuration
	Runtime   RuntimeType     `json:"runtime,omitempty"`   // Runtime type used
	Image     string          `json:"image,omitempty"`     // Docker image (for docker runtime)
	Resources *ResourceLimits `json:"resources,omitempty"` // Resource limits

	// Runtime information (not serialized to JSON)
	PID         int    `json:"-"`
	MountPoint  string `json:"-"`
	ContainerID string `json:"-"` // Docker container ID (for docker runtime)
}

Sandbox represents an isolated execution environment.

type SandboxError

type SandboxError struct {
	SandboxID string
	Op        string
	Err       error
}

SandboxError represents a sandbox-related error with context.

func (*SandboxError) Error

func (e *SandboxError) Error() string

func (*SandboxError) Unwrap

func (e *SandboxError) Unwrap() error

type SandboxStatus

type SandboxStatus string

SandboxStatus represents the current state of a sandbox.

const (
	StatusPending SandboxStatus = "pending"
	StatusRunning SandboxStatus = "running"
	StatusStopped SandboxStatus = "stopped"
	StatusError   SandboxStatus = "error"
)

type Session

type Session struct {
	ID        string        `json:"id"`
	SandboxID string        `json:"sandbox_id"`
	Status    SessionStatus `json:"status"`
	Shell     string        `json:"shell"` // Shell binary, e.g., "/bin/bash"
	CreatedAt time.Time     `json:"created_at"`
	ClosedAt  *time.Time    `json:"closed_at,omitempty"`

	// Runtime information (not serialized to JSON)
	PID int `json:"-"` // PID of the shell process
}

Session represents a stateful shell session within a sandbox. Unlike Exec which creates a new process for each command, a Session maintains a persistent shell process that preserves working directory, environment variables, and background processes.

type SessionConfig

type SessionConfig struct {
	Shell string            // Shell binary to use (default: /bin/bash)
	Env   map[string]string // Initial environment variables
}

SessionConfig contains configuration for creating a new session.

type SessionError

type SessionError struct {
	SessionID string
	Op        string
	Err       error
}

SessionError represents a session-related error with context.

func (*SessionError) Error

func (e *SessionError) Error() string

func (*SessionError) Unwrap

func (e *SessionError) Unwrap() error

type SessionExecRequest

type SessionExecRequest struct {
	Command string        `json:"command"`
	Timeout time.Duration `json:"timeout,omitempty"`
}

SessionExecRequest represents a command execution request within a session.

type SessionStatus

type SessionStatus string

SessionStatus represents the current state of a shell session.

const (
	SessionStatusActive SessionStatus = "active"
	SessionStatusClosed SessionStatus = "closed"
)

Jump to

Keyboard shortcuts

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