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 levelWhen usefulWhat it does not solve
Separate branchSmall changes with required reviewDoes not isolate the local environment
Git worktreeLarge or experimental changesDoes not isolate environment, ports, or local databases
ContainerDependencies, runtime, and test servicesIs not a complete virtual-machine boundary
Virtual machineEspecially risky system experimentsRequires 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

  1. Classify task risk.
  2. Choose a branch, worktree, container, or VM.
  3. Move work out of the main copy.
  4. Connect only a test database and synthetic data.
  5. Limit commands, paths, network, and secrets.
  6. Run build, tests, and side-effect checks.
  7. Review the diff and make a separate human decision.
  8. Remove temporary containers, data, worktrees, and unnecessary branches afterward.

Choose isolation by scenario

ScenarioSuggested boundary
Documentation or small editSeparate branch
Significant code changeBranch or worktree
Dependency update and complex buildWorktree with a container
Migration or mass updateWorktree, test database, and synthetic data
Writable MCP or unverified toolContainer or VM
Mass deletionDisposable 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