Sandbox Testing
Overview
Sandbox testing allows Pensar to spin up your entire application in an isolated, ephemeral environment for security testing. By providing a Docker Compose file or letting Pensar automatically configure your development environment, you can test your application safely without impacting production systems.
Sandbox testing is the optimal approach for applications where the development environment can be easily containerized and started programmatically.
How Sandbox Testing Works
Pensar creates isolated environments on-demand for each pentest:
Environment Preparation
Pensar clones your repository into an isolated sandbox environment with full network isolation and resource constraints.
Service Discovery & Startup
The AI agent identifies your application’s service requirements: - Looks for
docker-compose.yml or docker-compose.yaml in your repository - If found,
uses your existing configuration - If not found, analyzes your codebase to
detect required services (databases, caches, message queues) - Automatically
generates a Docker Compose configuration if needed - Starts all services and
waits for health checks to pass
Security Testing
Once the environment is healthy, whitebox testing is performed against the sandbox with full source code context and dynamic analysis.
Key Benefits
Sandbox testing provides unique advantages for security testing:
Spin up isolated environments in real-time for each scan without affecting production or staging systems. Test destructive exploits safely.
During auto-remediation, replay exploit proof-of-concepts in real-time to confirm vulnerabilities are fixed. This verification loop ensures patches work before creating pull requests.
Test aggressively without worrying about data corruption, service disruption, or production incidents. All testing is fully isolated.
Every scan runs in a fresh, identical environment. Eliminates environmental differences that can cause false positives or missed vulnerabilities.
Safely test destructive exploits like SQL injection, file uploads, command injection, and other attacks that modify system state.
The AI agent automatically handles environment configuration, dependency installation, database migrations, and service startup.
Docker Compose Configuration
Using Your Existing Configuration
If your repository contains a docker-compose.yml or docker-compose.yaml file, Pensar will use it automatically:
Ensure your Docker Compose file includes health checks for all critical services. This allows Pensar to wait for services to be fully ready before starting security tests.
Automatic Configuration Generation
If no Docker Compose file is found, Pensar analyzes your codebase to automatically generate one:
Dependency Detection
The AI agent scans your code for: - Database connections (PostgreSQL, MySQL, MongoDB, etc.) - Cache services (Redis, Memcached) - Message queues (RabbitMQ, Kafka) - Search engines (Elasticsearch, OpenSearch) - Other infrastructure dependencies
Best Practices for Docker Compose
Use Health Checks
Define health checks for all services to ensure they’re fully ready:
Health checks prevent Pensar from starting tests before services are ready.
Use Service Dependencies
Specify service dependencies with conditions:
This ensures proper startup order and prevents race conditions.
Seed Test Data
Include database seeding in your setup:
Test data helps the AI agent understand your data model and test more effectively.
Expose Necessary Ports
Expose all ports that Pensar needs to test:
This ensures all endpoints are accessible for testing.
Sandbox Testing vs. Live Environment Testing
Understanding when to use each approach:
When to Use Sandbox Testing
Sandbox testing is ideal when:
Simple Dev Environment Setup
Your application can be started with:
- A Docker Compose file
- A simple shell script
- Standard development commands (
npm start,rails server, etc.)
If your entire dev environment can run locally with minimal configuration, sandbox testing is perfect.
Testing Destructive Exploits
You want to safely test exploits that:
- Modify or delete data
- Upload malicious files
- Execute system commands
- Cause service disruptions
Sandboxes allow aggressive testing without production risk.
Automated Remediation Verification
You’re using auto-remediation and want to:
- Replay POCs to verify fixes work
- Iterate on patches until confirmed resolved
- Have high confidence in automated fixes
Sandbox environments enable real-time verification loops.
Consistent Testing
You need:
- Identical environments for every scan
- No environmental drift
- Reproducible results
- Fresh state for each test run
When to Use Live Environment Testing
For organizations with more complex applications where the dev environment can’t simply be spun up with a Docker Compose file or similar simple approach, we recommend pentesting against live domains instead using the whitebox testing → live environment testing approach.
Live environment testing is better when: - Your application requires complex infrastructure (Kubernetes clusters, cloud services) - Third-party integrations can’t be easily mocked - Database migrations or data setup is complex - Microservices architecture with many dependencies - Enterprise systems with specialized hardware/software
With live environment testing:
- Provide your staging or production domain URLs
- Verify domain ownership via DNS TXT records
- Configure authentication credentials if needed
- Pensar tests against the live environment with source code insights
Learn more about live environment testing in the whitebox testing guide.
Sandbox Security & Isolation
Pensar sandboxes are designed with multiple layers of security:
Sandboxes run in isolated networks with no access to internal infrastructure or other customer environments.
CPU, memory, and disk limits prevent resource exhaustion and ensure fair resource allocation.
All data is destroyed when the sandbox terminates. No persistence between scans.
Sandboxes automatically terminate after a maximum time to prevent runaway processes.
Configuration Options
Configure sandbox behavior in your project settings:
Sandbox Settings
- Enable/Disable Sandboxes: Turn sandbox testing on or off per project
- Startup Timeout: Maximum time to wait for environment to become healthy (default: 10 minutes)
- Resource Limits: CPU and memory allocation for the sandbox
- Port Mapping: Additional ports to expose beyond those in Docker Compose
Environment Variables
Provide environment variables needed for your application:
- Secrets: API keys, database credentials, third-party tokens
- Configuration: Feature flags, environment settings
- Testing Overrides: Disable external services, use test mode
Secrets provided for sandbox testing are encrypted at rest and in transit, and are destroyed when the sandbox terminates.
Troubleshooting
Sandbox Won't Start
If your sandbox environment fails to start:
- Check the sandbox logs in the Pensar Console scan details
- Verify your Docker Compose file works locally
- Ensure health checks are properly configured
- Check for missing environment variables
- Review build logs for dependency installation errors
The AI agent automatically attempts to fix configuration issues, but complex problems may require manual intervention.
Services Not Healthy
If services fail health checks:
- Increase the
start_periodin health check configuration - Verify health check commands are correct
- Check service logs for startup errors
- Ensure dependencies are available (network, volumes)
Application Not Responding
If tests fail to reach your application:
- Verify ports are correctly exposed in Docker Compose
- Check that the application is listening on
0.0.0.0, notlocalhost - Review application logs for startup errors
- Ensure the application waits for dependencies before starting
Slow Environment Startup
If sandboxes take too long to start:
- Optimize Docker image sizes
- Use build caching effectively
- Pre-build images and push to a registry
- Reduce the number of dependencies
- Consider switching to live environment testing for very complex setups
Best Practices
Optimize for Fast Startup
Minimize sandbox startup time:
- Use lightweight base images
- Leverage Docker layer caching
- Pre-install dependencies in container images
- Use multi-stage builds
- Avoid unnecessary services in dev environment
Include Comprehensive Health Checks
Ensure all services have proper health checks: - Database connections are ready - Application server is accepting requests - Migrations have completed - External dependencies are available
Seed Realistic Test Data
Provide test data that represents your production data: - User accounts with different roles - Sample products, orders, content - Edge cases and boundary conditions - Data that exercises your business logic
Monitor Sandbox Performance
Track sandbox metrics over time:
- Average startup time
- Success/failure rates
- Resource utilization
- Testing duration
Use this data to optimize your configuration.
Next Steps
Learn about whitebox testing approaches including sandbox and live environment testing.
Discover how sandbox environments enable real-time verification of security fixes.
Configure live domains for testing when sandboxes aren’t suitable.
Set up authentication credentials for testing protected application areas.