Documentation
¶
Overview ¶
Package sandbox provides a Go API for executing programs inside a sandbox environment.
It is a thin, declarative wrapper over the sandbox tool, responsible only for configuration and process invocation. The sandbox executable defines all execution semantics and guarantees.
Sandbox tool documentation and usage:
https://github.com/Highload-fun/sandbox
Index ¶
- Variables
- type Sandbox
- func (s *Sandbox) AddEnv(value string) *Sandbox
- func (s *Sandbox) AddFile(src, dst string, withLibs bool) *Sandbox
- func (s *Sandbox) BuildExecArgs(path string, args []string) []string
- func (s *Sandbox) Command(path string, args ...string) *exec.Cmd
- func (s *Sandbox) CommandContext(ctx context.Context, path string, args ...string) *exec.Cmd
- func (s *Sandbox) ExecDir(dir string) *Sandbox
- func (s *Sandbox) MountDir(src, dst string) *Sandbox
- func (s *Sandbox) PassListener(addr, socketPath string) *Sandbox
- func (s *Sandbox) SaveUsageStat(filename string) *Sandbox
- func (s *Sandbox) SetCGroup(name string) *Sandbox
- func (s *Sandbox) SetCpuSet(set string) *Sandbox
- func (s *Sandbox) SetMemLimit(limit uint64) *Sandbox
- func (s *Sandbox) SetNoNewNet(v bool) *Sandbox
Constants ¶
This section is empty.
Variables ¶
var Path = "/usr/bin/sandbox"
Path points to the sandbox executable. It is used as the program invoked by exec.Command.
Functions ¶
This section is empty.
Types ¶
type Sandbox ¶
type Sandbox struct {
// contains filtered or unexported fields
}
Sandbox is a mutable builder that describes how a program should be executed inside a sandbox.
It accumulates filesystem mappings, environment configuration, resource limits, and execution parameters, which are later translated into sandbox tool arguments.
func (*Sandbox) AddEnv ¶
AddEnv adds an environment variable that will be visible to the sandboxed process.
func (*Sandbox) AddFile ¶
AddFile declares that a file from the host must be available inside the sandbox at the given location.
func (*Sandbox) BuildExecArgs ¶
BuildExecArgs converts the sandbox configuration into a complete argument list for the sandbox executable.
func (*Sandbox) Command ¶
Command constructs an exec.Cmd that runs a command inside the configured sandbox.
func (*Sandbox) CommandContext ¶
CommandContext is identical to Command, but allows the execution to be bound to a context.
func (*Sandbox) ExecDir ¶
ExecDir sets the working directory inside the sandbox where the command will be executed.
func (*Sandbox) MountDir ¶
MountDir declares that a directory from the host filesystem must be accessible inside the sandbox.
func (*Sandbox) PassListener ¶
PassListener makes the sandbox listen on addr in its network namespace and pass the listener to the unix socket at socketPath.
func (*Sandbox) SaveUsageStat ¶
SaveUsageStat enables persisting execution statistics after the process exits.
func (*Sandbox) SetMemLimit ¶
SetMemLimit limits memory usage of the sandboxed process.
func (*Sandbox) SetNoNewNet ¶
SetNoNewNet configures whether the sandboxed process is isolated from the network.