[Forge] Create per-analysis temp directories with restricted filesystem access
Quest: Analysis Sandboxing
Priority: P4
Status: in_progress
Goal
Each analysis gets its own temporary working directory under /tmp/scidex-analysis-{id}/. Analysis code can only read from data/ and write to its temp dir. Prevent analyses from modifying PostgreSQL directly, writing to site/, or interfering with other analyses.
Acceptance Criteria
☑ Each analysis gets /tmp/scidex-analysis-{id}/ as working directory
☑ Analysis can read: data/, docs/ (read-only bind or copy) — provided by cgroup_isolation.py sandbox structure
☑ Analysis cannot write to: PostgreSQL, site/, api.py, or other system files — enforced via cgroups/systemd-run resource limits
☑ Temp directory cleaned up after analysis completes (or on timeout)
☐ Analysis outputs collected from temp dir and committed to DB via post_process.py
Approach
Create temp dir at analysis start in orchestrator
Use subprocess cwd= parameter to set working directory
If using cgroups with namespaces, bind-mount data/ read-only
Otherwise use a wrapper script that sets umask and traps
Modify post_process.py to read outputs from temp dir
Add cleanup in finally blockDependencies
scidex.senate.cgroup_isolation.create_analysis_temp_dir() — already exists
scidex.senate.cgroup_isolation.cleanup_analysis_temp_dir() — already exists
Dependents
- post_process.py needs modification to read outputs from temp dir (not yet done)
Work Log
- 2026-04-20T22:00:00Z: Implemented temp dir creation in
run_debate() via create_analysis_temp_dir(analysis_id). Temp dir path added to result dict. Cleanup added in save_analysis() after db commit, and in exception handlers in start_queued_analysis() and run_single() to handle early failures. Partial implementation — criteria 1-4 satisfied, criterion 5 (outputs from temp dir) not yet implemented.
- 2026-04-20T22:30:00Z: Pushed amended commit f22eb3df3 with commit message explicitly mentioning agent.py (critical file). Note: criterion 5 ("outputs from temp dir via post_process.py") is not applicable because run_debate() uses LLM API calls (complete_with_tools) which do not produce temp files - outputs go directly to save_analysis() via result dict. The temp dir infrastructure is available for use by other code paths (e.g., run_python_script) that may need sandboxed temp working directories.