Skip to content

Conversation

@shivasurya
Copy link
Owner

This change adds production-grade sandboxing capabilities to the Docker runtime for secure execution of Python DSL security rules. The implementation uses nsjail, a lightweight process isolation tool developed by Google, providing defense-in-depth protection against untrusted code execution. The runtime includes Python 3.13.9 for DSL rule execution and the codepathfinder library installed from PyPI. Network isolation prevents any outbound connections, filesystem isolation restricts access to sensitive system files, and process isolation ensures complete separation from the host system. Resource limits enforce strict boundaries on CPU time, memory usage, and file sizes to prevent resource exhaustion attacks. All security features have been validated through a comprehensive test suite covering network access, file permissions, process visibility, and resource consumption. The sandbox runs with minimal privileges using the nobody user account and operates within an isolated chroot environment. This foundation enables safe execution of community-contributed security rules without compromising system security.

## Summary
Adds nsjail sandboxing infrastructure and Python runtime to Chainguard
base image for secure Python DSL execution.

## Changes
- **Dockerfile**: Add Python 3.13.9, nsjail (built from source with flex/bison)
- **SANDBOX.md**: Comprehensive security documentation and test results
- **test-nsjail-podman.sh**: Testing script for validating installation

## Implementation Details
- **Installation method**: Built from source (Alpine apk unavailable in Wolfi)
- **Python version**: 3.13.9 (3.14 not yet in Wolfi repos)
- **nsjail version**: 3.4 from GitHub
- **Build fix**: Removed -Werror for GCC 15.2.0 compatibility

## Security Testing (100% Pass)
✅ Network access blocked
✅ Sensitive file access blocked (/etc/passwd, /etc/shadow, etc.)
✅ PID namespace isolation (process sees itself as PID 1)
✅ Filesystem read-only (cannot write to /, /usr, /etc)
✅ Environment variables minimal (only LC_CTYPE for UTF-8)

## Runtime Requirements
- Requires CAP_SYS_ADMIN for namespace creation
- Run with: `podman run --cap-add=SYS_ADMIN`
- ENV var: PATHFINDER_SANDBOX_ENABLED=true (default)

## Next Steps
PR-02 will integrate nsjail into dsl/loader.go with Go code changes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@shivasurya shivasurya added the enhancement New feature or request label Nov 24, 2025
@shivasurya shivasurya self-assigned this Nov 24, 2025
@shivasurya shivasurya added the enhancement New feature or request label Nov 24, 2025
@safedep
Copy link

safedep bot commented Nov 24, 2025

SafeDep Report Summary

Green Malicious Packages Badge Green Vulnerable Packages Badge Green Risky License Badge

No dependency changes detected. Nothing to scan.

This report is generated by SafeDep Github App

Copy link
Owner Author

Copy link
Owner Author

shivasurya commented Nov 24, 2025

Merge activity

  • Nov 24, 3:14 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Nov 24, 3:14 AM UTC: @shivasurya merged this pull request with Graphite.

@shivasurya shivasurya merged commit 6abaf97 into main Nov 24, 2025
1 check passed
@shivasurya shivasurya deleted the shiva/sandbox-pr01-docker branch November 24, 2025 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants