docs/guides/agent/agent_quickstarts/sandbox_quickstart.md
A secure, pluggable code execution backend designed for RAGFlow and other applications requiring isolated code execution environments.
RAGFlow's CodeExec agent component depends on a sandbox provider to run Python and JavaScript code. Configure one of the providers below before using CodeExec.
The architecture consists of isolated Docker base images for each supported language runtime, managed by the executor manager service. The executor manager orchestrates sandboxed code execution using gVisor for syscall interception and optional seccomp profiles for enhanced syscall filtering.
RAGFlow supports two sandbox provider types:
self_managed: Runs code inside Docker-managed sandbox containers. Use this for the standard RAGFlow sandbox deployment.local: Runs code as local Python or Node.js subprocesses. Use this only in trusted development environments.29.1.0 or higher to stay compatible with the latest Docker daemons.:::tip NOTE
The error message client version 1.43 is too old. Minimum supported API version is 1.44 indicates that your executor manager image's built-in Docker CLI version is lower than 29.1.0 required by the Docker daemon in use.
:::
The sandbox uses isolated base images for secure containerized execution environments.
Build the runtime base images:
docker build -t sandbox-base-python:latest ./sandbox_base_image/python
docker build -t sandbox-base-nodejs:latest ./sandbox_base_image/nodejs
Alternatively, build all base images at once using the Makefile:
make build
Build the executor manager image:
docker build -t sandbox-executor-manager:latest ./executor_manager
If you do not need to customize runtime dependencies, pull the published base images and tag them with the names used by standalone Docker Compose:
docker pull infiniflow/sandbox-base-python:latest
docker pull infiniflow/sandbox-base-nodejs:latest
docker tag infiniflow/sandbox-base-python:latest sandbox-base-python:latest
docker tag infiniflow/sandbox-base-nodejs:latest sandbox-base-nodejs:latest
Then restart the standalone sandbox services:
docker compose -f docker-compose.yml down
docker compose -f docker-compose.yml up -d
Verify that gVisor is properly installed and operational.
Configure the .env file located at docker/.env:
SANDBOX_ENABLED=1.SANDBOX_PROVIDER_TYPE=self_managed or SANDBOX_PROVIDER_TYPE=local.self_managed, include sandbox in COMPOSE_PROFILES.local, uncomment and adjust the SANDBOX_LOCAL_* variables.Add the following entry to your /etc/hosts file to resolve the executor manager service:
127.0.0.1 es01 infinity mysql minio redis sandbox-executor-manager
Start the RAGFlow service as usual.
The variables in docker/.env are grouped by scope.
These variables apply to sandbox support in general:
SANDBOX_ENABLED: Enables sandbox support in RAGFlow.SANDBOX_PROVIDER_TYPE: Selects the active provider. Supported values are self_managed and local.SANDBOX_HOST: The executor manager host used by the self-managed provider and the legacy HTTP fallback.SANDBOX_ARTIFACT_BUCKET: MinIO bucket used for files generated by sandbox code.SANDBOX_ARTIFACT_EXPIRE_DAYS: Number of days before sandbox artifacts expire.These variables apply when SANDBOX_PROVIDER_TYPE=self_managed:
COMPOSE_PROFILES: Must include sandbox to start sandbox-executor-manager with RAGFlow.SANDBOX_EXECUTOR_MANAGER_IMAGE: Docker image for the executor manager service.SANDBOX_EXECUTOR_MANAGER_POOL_SIZE: Number of Python and Node.js sandbox containers kept in the pool.SANDBOX_BASE_PYTHON_IMAGE: Python runtime image used by executor-managed containers.SANDBOX_BASE_NODEJS_IMAGE: Node.js runtime image used by executor-managed containers.SANDBOX_EXECUTOR_MANAGER_PORT: Host port exposed by the executor manager.SANDBOX_ENABLE_SECCOMP: Enables the optional seccomp profile for sandbox containers.SANDBOX_MAX_MEMORY: Memory limit for each sandbox runtime container.SANDBOX_TIMEOUT: Default execution timeout.These variables apply when SANDBOX_PROVIDER_TYPE=local:
SANDBOX_LOCAL_ENABLED: Explicitly enables local code execution.SANDBOX_LOCAL_PYTHON_BIN: Python executable used by local execution.SANDBOX_LOCAL_NODE_BIN: Node.js executable used by local execution.SANDBOX_LOCAL_WORK_DIR: Working directory for local execution files and artifacts.SANDBOX_LOCAL_TIMEOUT: Maximum local execution time in seconds.SANDBOX_LOCAL_MAX_MEMORY_MB: Address-space memory limit for local child processes.SANDBOX_LOCAL_MAX_OUTPUT_BYTES: Maximum stdout and stderr size.SANDBOX_LOCAL_MAX_ARTIFACTS: Maximum number of artifacts collected after execution.SANDBOX_LOCAL_MAX_ARTIFACT_BYTES: Maximum size for each artifact.OPENBLAS_NUM_THREADS, OMP_NUM_THREADS, MKL_NUM_THREADS, NUMEXPR_NUM_THREADS, BLIS_NUM_THREADS, VECLIB_MAXIMUM_THREADS: Optional native math library thread limits for local Python subprocesses.Initialize the environment variables:
cp .env.example .env
Launch the sandbox services with Docker Compose:
docker compose -f docker-compose.yml up
Test the sandbox setup:
source .venv/bin/activate
export PYTHONPATH=$(pwd)
uv pip install -r executor_manager/requirements.txt
uv run tests/sandbox_security_tests_full.py
Run all setup, build, launch, and tests with a single command:
make
To follow logs of the executor manager container:
docker logs -f sandbox-executor-manager
Or use the Makefile shortcut:
make logs