A sandbox reduces the consequence of error
Permissions define allowed actions; a sandbox defines where they run. Use a sandbox not only to deny commands but to reduce the impact of a mistake.
Before starting, define allowed paths and commands, forbidden system or production areas, network access, and the data type that may be handled.
| Isolation level | When useful | What it does not solve |
|---|---|---|
| Separate branch | Small changes with required review | Does not isolate the local environment |
| Git worktree | Large or experimental changes | Does not isolate environment, ports, or local databases |
| Container | Dependencies, runtime, and test services | Is not a complete virtual-machine boundary |
| Virtual machine | Especially risky system experiments | Requires more resources and time |
Isolate code, environment, and data together
- Use a test database instead of production.
- Generate synthetic records.
- Pass fake credentials or only required environment values.
- Enable a test profile.
- Do not assume a sanitized production dump is automatically safe.
Practical sandbox workflow
- Classify task risk.
- Choose a branch, worktree, container, or VM.
- Move work out of the main copy.
- Connect only a test database and synthetic data.
- Limit commands, paths, network, and secrets.
- Run build, tests, and side-effect checks.
- Review the diff and make a separate human decision.
- Remove temporary containers, data, worktrees, and unnecessary branches afterward.
Choose isolation by scenario
| Scenario | Suggested boundary |
|---|---|
| Documentation or small edit | Separate branch |
| Significant code change | Branch or worktree |
| Dependency update and complex build | Worktree with a container |
| Migration or mass update | Worktree, test database, and synthetic data |
| Writable MCP or unverified tool | Container or VM |
| Mass deletion | Disposable environment with a controlled data set |
A sandbox does not replace other controls
- A dry run shows a plan but not every side effect.
- A backup helps recovery but does not make an error safe.
- Staging may be shared and insufficiently isolated.
- Git, tests, review, and human control remain required.
Canonical lesson source · JavaRush
Open JavaRush material