Documentation
¶
Index ¶
- Variables
- type Arg
- type ArgsType
- type BindMount
- type BubblewrapCommandOptions
- type BubblewrapConfiguration
- type BubblewrapSandbox
- func (b *BubblewrapSandbox) Clear() error
- func (b *BubblewrapSandbox) ExecuteWithOptions(ctx context.Context, options *BubblewrapCommandOptions) (*types.Result, error)
- func (b *BubblewrapSandbox) Run(ctx context.Context, cmd string) (*types.Result, error)
- func (b *BubblewrapSandbox) RunScript(ctx context.Context, source string) (*types.Result, error)
- func (b *BubblewrapSandbox) RunSource(ctx context.Context, source string) (*types.Result, error)
- func (b *BubblewrapSandbox) Start() error
- func (b *BubblewrapSandbox) Stop() error
- func (b *BubblewrapSandbox) Wait() error
- type Configuration
- type DockerConfiguration
- type DockerSourceOptions
- type Filter
- type Rule
- type Sandbox
- type SandboxDocker
- func (s *SandboxDocker) Clear() error
- func (s *SandboxDocker) Run(ctx context.Context, cmd string) (*types.Result, error)
- func (s *SandboxDocker) RunScript(ctx context.Context, source string, interpreter string) (*types.Result, error)
- func (s *SandboxDocker) RunSource(ctx context.Context, source string, interpreter string) (*types.Result, error)
- func (s *SandboxDocker) RunSourceWithOptions(ctx context.Context, source string, opts DockerSourceOptions) (*types.Result, error)
- func (s *SandboxDocker) Start() error
- func (s *SandboxDocker) Stop() error
- func (s *SandboxDocker) Wait() error
- type SandboxLinux
- func (s *SandboxLinux) Clear() error
- func (s *SandboxLinux) Run(ctx context.Context, cmd string) (*types.Result, error)
- func (s *SandboxLinux) RunScript(ctx context.Context, source string) (*types.Result, error)
- func (s *SandboxLinux) RunSource(ctx context.Context, source string, interpreter string) (*types.Result, error)
- func (s *SandboxLinux) Start() error
- func (s *SandboxLinux) Stop() error
- func (s *SandboxLinux) Wait() error
- type Symlink
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotImplemented = errors.New("not implemented") ErrAgentRequired = errors.New("requires agent installed on the sandbox") )
Functions ¶
This section is empty.
Types ¶
type BubblewrapCommandOptions ¶ added in v0.1.1
type BubblewrapCommandOptions struct {
// The command to execute
Command string
// Arguments for the command
Args []string
// Per-command bind mounts (e.g., source file location -> sandbox location)
CommandBinds []BindMount
// Working directory for this command
WorkingDir string
// Change to this directory before running
Chdir string
// Per-command environment variables (merged with static ones)
Environment map[string]string
// Input for stdin
Stdin string
}
BubblewrapCommandOptions holds per-command configuration
type BubblewrapConfiguration ¶ added in v0.1.1
type BubblewrapConfiguration struct {
// Base directory for temporary sandbox files
TempDir string
// Static namespace options (applied to all commands)
// Static security options (applied to all commands)
NewSession bool // Create a new session (prevents TIOCSTI attacks)
UID int // UID to run as inside the sandbox
GID int // GID to run as inside the sandbox
// Seccomp filter file
SeccompFile string
// Static bind mounts (read-only system directories)
ReadOnlySystemBinds []BindMount
// Static environment variables
Environment map[string]string
// Enable host filesystem access (read-only)
HostFilesystem bool
}
BubblewrapConfiguration holds the general configuration for bubblewrap sandboxing
type BubblewrapSandbox ¶ added in v0.1.1
type BubblewrapSandbox struct {
// contains filtered or unexported fields
}
BubblewrapSandbox implements sandboxing using bubblewrap (bwrap)
func NewBubblewrapSandbox ¶ added in v0.1.1
func NewBubblewrapSandbox(ctx context.Context, config *BubblewrapConfiguration) (*BubblewrapSandbox, error)
NewBubblewrapSandbox creates a new bubblewrap sandbox
func (*BubblewrapSandbox) Clear ¶ added in v0.1.1
func (b *BubblewrapSandbox) Clear() error
Clear cleans up the temp directory
func (*BubblewrapSandbox) ExecuteWithOptions ¶ added in v0.1.1
func (b *BubblewrapSandbox) ExecuteWithOptions(ctx context.Context, options *BubblewrapCommandOptions) (*types.Result, error)
ExecuteWithOptions executes a command with specific per-command options
func (*BubblewrapSandbox) Run ¶ added in v0.1.1
Run executes a command in the bubblewrap sandbox with default options
func (*BubblewrapSandbox) RunScript ¶ added in v0.1.1
RunScript runs a script in the bubblewrap sandbox
func (*BubblewrapSandbox) RunSource ¶ added in v0.1.1
RunSource executes source code in the bubblewrap sandbox It creates a specific source directory, places the script file inside, and mounts only that directory
func (*BubblewrapSandbox) Start ¶ added in v0.1.1
func (b *BubblewrapSandbox) Start() error
Start starts the sandbox (no-op for bubblewrap as it runs per-command)
func (*BubblewrapSandbox) Stop ¶ added in v0.1.1
func (b *BubblewrapSandbox) Stop() error
Stop stops the sandbox (no-op for bubblewrap as each command runs independently)
func (*BubblewrapSandbox) Wait ¶ added in v0.1.1
func (b *BubblewrapSandbox) Wait() error
Wait waits for the sandbox to finish (no-op for bubblewrap)
type Configuration ¶
type Configuration struct {
Rules []Rule
}
type DockerConfiguration ¶ added in v0.1.1
type DockerConfiguration struct {
Image string // Docker image to use (e.g., "ubuntu:20.04", "alpine:latest")
WorkingDir string // Working directory inside container
Environment map[string]string // Environment variables
NetworkMode string // Network mode (bridge, host, etc.)
NetworkDisabled bool // Disable networking entirely
User string // User to run as inside container
Memory string // Memory limit (e.g., "512m", "1g")
CPULimit string // CPU limit (e.g., "0.5", "1.0")
Timeout time.Duration // Command timeout
Remove bool // Whether to remove container after execution
}
DockerConfiguration represents the configuration for Docker sandbox
type DockerSourceOptions ¶ added in v0.1.1
type DockerSourceOptions struct {
// Interpreter runs the source file. If it is empty or the source starts
// with a shebang, the source file runs directly.
Interpreter string
// InterpreterArgs are passed to Interpreter before the source path.
InterpreterArgs []string
// Args are passed to the source after its path.
Args []string
// Stdin is copied to the standard input of the source until EOF or
// until the container exits. If nil, the container has no standard
// input. A read from Stdin can still be pending when the run returns.
Stdin io.Reader
}
DockerSourceOptions holds the per-run inputs of RunSourceWithOptions.
type Filter ¶
type Filter string
const ( PrivateTmp Filter = "PrivateTmp" PrivateNetwork Filter = "PrivateNetwork" SELinuxContext Filter = "SELinuxContext" NoNewPrivileges Filter = "NoNewPrivileges" ProtectSystem Filter = "ProtectSystem" ProtectHome Filter = "ProtectHome" ProtectDevices Filter = "ProtectDevices" CapabilityBoundingSet Filter = "CapabilityBoundingSet" ReadWriteDirectories Filter = "ReadWriteDirectories" ReadOnlyDirectories Filter = "ReadOnlyDirectories" InaccessibleDirectories Filter = "InaccessibleDirectories" ProtectKernelTunables Filter = "InaccessibleDirectories" ProtectKernelModules Filter = "ProtectKernelModules" ProtectControlGroups Filter = "ProtectControlGroups" RestrictNamespaces Filter = "RestrictNamespaces" MemoryDenyWriteExecute Filter = "MemoryDenyWriteExecute" RestrictRealtime Filter = "RestrictRealtime" PrivateMounts Filter = "PrivateMounts" DynamicUser Filter = "DynamicUser" SystemCallFilter Filter = "SystemCallFilter" )
type Sandbox ¶
type SandboxDocker ¶ added in v0.1.1
type SandboxDocker struct {
// contains filtered or unexported fields
}
SandboxDocker implements the Sandbox interface using Docker containers
func NewDockerSandbox ¶ added in v0.1.1
func NewDockerSandbox(ctx context.Context, config *DockerConfiguration) (*SandboxDocker, error)
NewDockerSandbox creates a new Docker-based sandbox
func (*SandboxDocker) Clear ¶ added in v0.1.1
func (s *SandboxDocker) Clear() error
Clear cleans up Docker resources (containers, images, etc.)
func (*SandboxDocker) Run ¶ added in v0.1.1
Run executes a command in the Docker container (synchronous execution)
func (*SandboxDocker) RunScript ¶ added in v0.1.1
func (s *SandboxDocker) RunScript(ctx context.Context, source string, interpreter string) (*types.Result, error)
RunScript executes a script in the Docker container
func (*SandboxDocker) RunSource ¶ added in v0.1.1
func (s *SandboxDocker) RunSource(ctx context.Context, source string, interpreter string) (*types.Result, error)
RunSource writes source code to a temporary file inside the container and executes it. The interpreter can include arguments, such as "python3 -u".
func (*SandboxDocker) RunSourceWithOptions ¶ added in v0.1.1
func (s *SandboxDocker) RunSourceWithOptions( ctx context.Context, source string, opts DockerSourceOptions, ) (*types.Result, error)
RunSourceWithOptions writes source code to a temporary file inside the container and executes it with the arguments and stdin in opts.
func (*SandboxDocker) Start ¶ added in v0.1.1
func (s *SandboxDocker) Start() error
Start is not implemented for Docker sandbox as it's stateless
func (*SandboxDocker) Stop ¶ added in v0.1.1
func (s *SandboxDocker) Stop() error
Stop is not implemented for Docker sandbox as it's stateless
func (*SandboxDocker) Wait ¶ added in v0.1.1
func (s *SandboxDocker) Wait() error
Wait is not implemented for Docker sandbox as it's stateless
type SandboxLinux ¶
type SandboxLinux struct {
Config *Configuration
// contains filtered or unexported fields
}
Sandbox native on linux
func (*SandboxLinux) RunScript ¶ added in v0.1.1
RunScript executes a script or source code in the sandbox