sandbox

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 12 Imported by: 0

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
}

@sk-task mcp-sandbox#T3.2: DockerProvider — Docker-based sandbox (AC-006, AC-009) 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).

func (*DockerProvider) Execute

func (p *DockerProvider) Execute(ctx context.Context, code string, env map[string]string) (string, error)

Execute runs the given code in a Docker container.

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
}

@sk-task mcp-sandbox#T1.1: sandbox.Provider interface (AC-007, AC-010) 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
}

@sk-task mcp-sandbox#T2.2: WasmProvider — wazero-based WASM sandbox (AC-004, AC-005) 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.

func (*WasmProvider) Execute

func (p *WasmProvider) Execute(ctx context.Context, code string, env map[string]string) (string, error)

Execute compiles Go source to WASM and runs it in a sandboxed wazero runtime.

Jump to

Keyboard shortcuts

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