Kernel-enforced sandboxing for command execution
Uses bubblewrap or Docker to restrict file access at OS level
Constants
DEFAULT_MAX_FILE_SIZE = 1000000
DOCKER_DEFAULT_IMAGE = "alpine:latest"
DOCKER_MEMORY_LIMIT = "512m"
DOCKER_NAME_PREFIX = "autobot-sandbox-"
EXTRA_SEARCH_PATHS = ["/usr/local/bin", "/opt/homebrew/bin"]
SANDBOX_DOCKERFILE = "Dockerfile.sandbox"
SANDBOX_IMAGE_TAG = "autobot-sandbox"
SYSTEM_CONFIG_PATHS = ["/etc/alternatives", "/etc/ld.so.cache", "/etc/ld.so.conf", "/etc/ld.so.conf.d", "/etc/resolv.conf", "/etc/hosts", "/etc/nsswitch.conf", "/etc/ssl", "/etc/ca-certificates", "/etc/localtime", "/etc/passwd", "/etc/group", "/etc/matplotlibrc"]
/usr/bin/python3 and friends are symlinks into /etc/alternatives on Debian-based hosts
Class methods
available?
Check if sandboxing is available
Sourcebuild_sandbox_image(dockerfile :
Path) :
Bool Build the sandbox Docker image from a Dockerfile.
Sourcedetect
Detect available sandbox tool (memoized)
Sourcedetect_override
Test override for sandbox detection (set to nil to use real detection)
Sourcedetect_override=(detect_override : Type | Nil)
Test override for sandbox detection (set to nil to use real detection)
Sourcedocker_image
Custom Docker image (set from config at startup)
Sourcedocker_image=(docker_image :
String |
Nil)
Custom Docker image (set from config at startup)
Sourceexec(command :
String, workspace :
Path, timeout :
Int32, max_output_size :
Int32 =
CommandRunner::DEFAULT_MAX_OUTPUT) :
CommandRunner::Result Execute a shell command in sandbox (for arbitrary commands with pipes/redirects).
Sourceexec_program(program :
String, args :
Array(
String), workspace :
Path, timeout :
Int32, max_output_size :
Int32 =
CommandRunner::DEFAULT_MAX_OUTPUT) :
CommandRunner::Result Execute a program with explicit args in sandbox (no shell interpretation).
Safer than exec for structured operations like file reads.
SourceForward explicitly allowed environment variables to Docker container.
Only variables listed in sandbox_env config are forwarded.
SourceRead a file and return its contents as base64-encoded string.
Safe for binary files (images, GIFs, documents).
Sourcerequire_sandbox!
Require sandbox or raise clear error
Sourceresolve_sandbox_image(config_dir :
Path) :
Nil Resolve the Docker image to use, checking for a Dockerfile.sandbox
in the given directory. If found and no explicit docker_image is set,
builds and caches the image automatically.
Sourceresolve_type(config :
String) :
Type Resolve sandbox type from config string
Sourcesandbox_env
Env var names to forward into Docker containers (set from config at startup).
Only listed variables are forwarded — empty by default for security.
SourceEnv var names to forward into Docker containers (set from config at startup).
Only listed variables are forwarded — empty by default for security.
Source