This directory contains Docker-based sandbox environments for secure code execution in BioDSA agents.
biodsa_env/
├── python_sandbox/ # Python 3.12 execution environment
│ ├── Dockerfile # Docker image definition
│ ├── Pipfile # Python package dependencies
│ ├── build_sandbox.sh # Build script
│ └── build.log # Build output log (generated)
├── r_sandbox/ # R execution environment (coming soon)
│ └── README.md
└── README.md # This file
The Python sandbox provides an isolated environment with pre-installed data science packages for biomedical analysis.
- Docker Desktop or Docker Engine installed
- Docker daemon running (verify with
docker ps)
cd python_sandbox./build_sandbox.shIf you get a permission error, make the script executable first:
chmod +x build_sandbox.sh
./build_sandbox.shThe build runs in the background. Monitor progress with:
tail -f build.logBuild time: 5-10 minutes (depending on network speed and system resources)
Check that the image was created successfully:
docker images | grep biodsa-sandbox-pyExpected output:
biodsa-sandbox-py latest abc123def456 2 minutes ago 1.2GB
Run a quick test to verify Python and packages work:
docker run --rm biodsa-sandbox-py:latest python -c "import pandas, matplotlib, seaborn; print('✓ Sandbox working!')"You can add or modify Python packages to suit your analysis needs.
Open python_sandbox/Pipfile in your editor:
cd python_sandbox
nano Pipfile # or vim, code, etc.Add new packages under the [packages] section:
[packages]
# Existing packages
pytest = "*"
pandas = "*"
matplotlib = "*"
# ... other packages ...
# Add your custom packages below:
scipy = "*" # Scientific computing
networkx = "*" # Network analysis
biopython = "*" # Biological computation
xgboost = "*" # Gradient boosting
torch = "*" # Deep learningVersion specifications:
"*"- Install latest version (recommended)"==1.2.3"- Install specific version">=1.2.0"- Install minimum version or higher
Python version:
- Fixed at Python 3.12.11 (specified in
[requires]section) - Do not modify the Python version unless you rebuild the base Dockerfile
After saving your changes, rebuild the Docker image:
./build_sandbox.shThis will:
- ✅ Read your updated Pipfile
- ✅ Resolve dependencies and create Pipfile.lock
- ✅ Install all packages in the container
- ✅ Build a new
biodsa-sandbox-py:latestimage
Test that your new package is available:
# Example: Test scipy installation
docker run --rm biodsa-sandbox-py:latest python -c "import scipy; print(f'scipy version: {scipy.__version__}')"
# Example: Test multiple packages
docker run --rm biodsa-sandbox-py:latest python -c "import torch, networkx; print('✓ Custom packages installed!')"The default Python sandbox includes:
pandas- DataFrames and data manipulationnumpy- Numerical computing (installed as pandas dependency)pydantic- Data validation
matplotlib- Basic plottingseaborn- Statistical visualizationsplotly- Interactive plotskaleido- Static image export for plotlympld3- Interactive matplotlib figurespycomplexheatmap- Complex heatmapsridgeplot- Ridge plots
statsmodels- Statistical modelslifelines- Survival analysisscikit-learn- Machine learning
pytest- Testing frameworkjupyter- Jupyter notebook supporttabulate- Pretty tablestrio- Async I/O
pip- Package installer
- Base Image:
python:3.12-slim(minimal Debian with Python 3.12) - Package Manager:
pipenvfor reproducible builds - Installation: Packages installed system-wide (no virtual environment)
- Runtime: Container runs indefinitely with
sleep infinity
FROM python:3.12-slim # Lightweight Python base image
RUN apt-get update # Update system packages
RUN pip install pipenv==2023.11.17 # Install pipenv for dependency management
RUN mkdir /sandbox # Create working directory
COPY Pipfile /sandbox/ # Copy package specifications
WORKDIR /sandbox # Set working directory
ENV PIPENV_VENV_IN_PROJECT=false # Install packages globally
RUN pipenv lock && pipenv install --system --deploy # Lock deps and install
CMD ["sleep", "infinity"] # Keep container running- Name:
biodsa-sandbox-py:latest - Tag:
latest(overwritten on each build) - Working Directory:
/sandbox(inside container) - Execution Directory:
/workdir(mounted at runtime by BioDSA agents)
Problem: permission denied: './build_sandbox.sh'
chmod +x python_sandbox/build_sandbox.shProblem: Cannot connect to the Docker daemon
# Check if Docker is running
docker ps
# Start Docker (macOS/Windows: open Docker Desktop)
# Linux:
sudo systemctl start dockerProblem: Locking failed or dependency conflicts
# Check build.log for details
cat python_sandbox/build.log
# Solutions:
# 1. Remove version constraints (use "*")
# 2. Update pipenv
pip install --upgrade pipenv
# 3. Clean Docker cache and rebuild
docker system prune -a
./build_sandbox.shProblem: Build runs out of disk space
# Clean up old Docker images
docker system prune -a
# Check disk space
df -hProblem: Package import fails in sandbox
# Verify package is in Pipfile
cat python_sandbox/Pipfile
# Rebuild if needed
cd python_sandbox && ./build_sandbox.shProblem: Sandbox container won't start
# Check Docker logs
docker ps -a
docker logs <container_id>
# Remove old containers
docker container pruneR sandbox support is currently under development.
Status: Coming soon
Planned features:
- R 4.x base environment
- Bioconductor packages
- tidyverse ecosystem
- Statistical analysis libraries
Stay tuned for updates!
Only include packages you actually need. Smaller images:
- ✅ Build faster
- ✅ Use less disk space
- ✅ Start containers quicker
For production/research workflows, pin versions:
pandas = "==2.0.0"
scikit-learn = "==1.3.0"Remove unused images and containers:
# Remove stopped containers
docker container prune
# Remove unused images
docker image prune
# Remove everything (use with caution!)
docker system prune -aAlways test the sandbox after customization:
docker run --rm biodsa-sandbox-py:latest python -c "import your_package"- Docker Documentation: https://docs.docker.com/
- Pipenv Documentation: https://pipenv.pypa.io/
- Python Packaging: https://packaging.python.org/
For issues specific to BioDSA agents, see the main repository README.