feat: add data sandbox mode for isolated file operations#235
Open
lxasqjc wants to merge 3 commits intosnap-stanford:mainfrom
Open
feat: add data sandbox mode for isolated file operations#235lxasqjc wants to merge 3 commits intosnap-stanford:mainfrom
lxasqjc wants to merge 3 commits intosnap-stanford:mainfrom
Conversation
- Add sandbox_mode and sandbox_path parameters to A1 constructor - Enable automatic session folder creation when sandbox_mode=True - Modify run_python_repl to support working directory changes - Add get_sandbox_path() method for sandbox path retrieval - Include comprehensive documentation and examples - Update .gitignore to exclude sandbox directories This feature allows users to isolate file operations in dedicated sandbox directories, preventing clutter in the main workspace and enabling easy cleanup of generated files.
Contributor
Author
🎯 OverviewThis PR introduces sandbox mode functionality to Biomni, enabling isolated workspace management for file operations during agent execution. This addresses the need for clean, isolated environments when the agent creates files, plots, or other outputs during exploration and analysis tasks. ✨ Features🔒 Sandbox Mode
🛠️ API Enhancements
📋 Use CasesResearch & Experimentation# Perfect for exploratory data analysis
agent = A1(path='./data', sandbox_mode=True)
agent.go("Analyze this dataset and create visualizations...")
# All plots, CSV files, results saved to isolated session folderAutomated Workflows# Clean environment for each analysis run
agent = A1(
path='./data',
sandbox_mode=True,
sandbox_path=f'/tmp/analysis_{datetime.now().strftime("%Y%m%d")}'
)Safe Development# Test new analysis code without cluttering workspace
agent = A1(path='./data', sandbox_mode=True)
agent.go("Try this experimental analysis approach...")
# No risk of overwriting important files🚀 Usage ExamplesExample 1: Default Sandbox Modefrom biomni.agent import A1
# Enable sandbox with auto-generated session folder
agent = A1(
path='./data',
sandbox_mode=True,
commercial_mode=True
)
# All file operations will happen in: ./sandbox/session_YYYYMMDD_HHMMSS/
result = agent.go("""
Create a data analysis report with visualizations.
```python
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
# Generate sample data
data = np.random.randn(1000, 2)
df = pd.DataFrame(data, columns=['Feature1', 'Feature2'])
# Create analysis
summary = df.describe()
print("Dataset Summary:")
print(summary)
# Save summary to CSV
summary.to_csv('data_summary.csv')
# Create visualization
plt.figure(figsize=(10, 6))
plt.scatter(df['Feature1'], df['Feature2'], alpha=0.6)
plt.xlabel('Feature 1')
plt.ylabel('Feature 2')
plt.title('Feature Correlation Analysis')
plt.savefig('correlation_plot.png', dpi=300, bbox_inches='tight')
# List created files
import os
files = os.listdir('.')
print(f"Files created: {files}")""") Check where files were savedsandbox_path = agent.get_sandbox_path() """) 🔧 Implementation DetailsCore Changes
Technical Features
Backward Compatibility
📊 Configuration DisplayWhen sandbox mode is enabled, the agent configuration shows: 🧪 TestingThe implementation has been tested with:
📝 BenefitsFor Users
For Developers
🔄 Migration GuideNo migration needed! This is a purely additive feature. To start using sandbox mode: # Before (still works)
agent = A1(path='./data')
# After (new capability)
agent = A1(path='./data', sandbox_mode=True)📁 Files Changed
This feature enables cleaner, more organized biomedical research workflows while maintaining full backward compatibility with existing Biomni usage patterns. |
- Add automatic symbolic links to project data directories - Inject helper functions for absolute path access - Enhance configuration display with data access information - Ensure backward compatibility with existing relative paths Fixes issue where sandbox mode made project data inaccessible, causing FileNotFoundError for paths like './data/biomni_data/...' Now provides multiple data access methods: 1. Relative paths via automatic symlinks 2. get_project_path() helper function 3. Environment variables (__original_cwd__, etc.) All output files remain isolated in sandbox while maintaining seamless access to project data for analysis.
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This feature allows users to isolate file operations in dedicated sandbox directories, preventing clutter in the main workspace and enabling easy cleanup of generated files.