Documentation
¶
Overview ¶
Package sandbox provides sandboxed code execution via WASM (wazero) or Docker.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DockerConfig ¶
type DockerConfig struct {
// Image is the Docker image to use (default "python:3.11-slim").
Image string
// MemoryLimit is a Docker memory limit string (e.g. "512m", "1g"). Empty means no limit.
MemoryLimit string
// CPULimit is the CPU quota (e.g. 1.5 for 1.5 cores). 0 means no limit.
CPULimit float64
// Timeout is the maximum execution time (default 60s).
Timeout time.Duration
}
DockerConfig holds configuration for the DockerProvider.
type DockerProvider ¶
type DockerProvider struct {
// contains filtered or unexported fields
}
DockerProvider executes code in a Docker container.
func NewDockerProvider ¶
func NewDockerProvider(cfg ...DockerConfig) *DockerProvider
NewDockerProvider creates a new DockerProvider with the given configuration.
func (*DockerProvider) Close ¶
func (p *DockerProvider) Close() error
Close releases DockerProvider resources (no-op for Docker).
type Provider ¶
type Provider interface {
// Execute compiles and runs the given code in a sandboxed environment.
// Returns stdout+stderr as a single string, or an error if execution failed.
Execute(ctx context.Context, code string, env map[string]string) (string, error)
// Close releases any resources held by the provider.
Close() error
}
Provider defines the interface for sandboxed code execution.
type WasmConfig ¶
type WasmConfig struct {
// MemoryLimit is the maximum memory in bytes (default 128MB).
MemoryLimit uint64
// CPUTimeout is the maximum execution time (default 30s).
CPUTimeout time.Duration
}
WasmConfig holds configuration for the WasmProvider.
type WasmProvider ¶
type WasmProvider struct {
// contains filtered or unexported fields
}
WasmProvider executes Go source code compiled to WASM.
func NewWasmProvider ¶
func NewWasmProvider(cfg ...WasmConfig) *WasmProvider
NewWasmProvider creates a new WasmProvider with the given configuration.
func (*WasmProvider) Close ¶
func (p *WasmProvider) Close() error
Close cleans up the temporary directory.
Click to show internal directories.
Click to hide internal directories.