# Execution environments

An execution environment runs scans from a network your workstation does
not reach, or should not reach directly: a client's lab segment, an
internal network behind a jump host, a cloud subnet. It is a worker you
start there and approve here, for chosen vaults and networks only.

## Approving an environment

In **Settings › Execution environments**, choose **Approve environment**
and give it:

- a name;
- the networks it may send requests to, as CIDR ranges or addresses
  (`10.20.0.0/16`, `192.168.1.10`);
- the vaults it may scan.

Phantom shows its token once, inside the command that starts the worker.
The token is stored only as a hash. **Rotate token** issues a new one and
the old one stops working at once; **Disable** stops the environment
from taking work without removing it; **Remove** cancels its queued
scans.

## Starting the worker

On a machine inside the target network, with this repository and its
backend dependencies installed:

```bash
PHANTOM_WORKER_TOKEN=phx_... python -m scripts.scan_worker --server https://phantom.example.com
```

The worker only makes outgoing requests: to your Phantom address and to
the targets. Nothing needs to reach it. It polls for work every few
seconds; `--once` handles a single scan and exits.

## Running a scan there

In the new scan form, **Where to run** lists the environments approved
for the vault. A scan sent to an environment waits in the queue until its
worker takes it; this workstation never runs it. While it runs, its log,
progress and findings appear here as for any scan, and **Cancel** and
**Stop all active work** reach the worker on its next report.

## What the worker checks

Before every request, including each redirect hop:

1. the vault's scope, exactly as on the workstation;
2. the environment's networks: every address the host resolves to must
   be inside them, or the request is not sent and the host is listed in
   the scan summary under `outside_networks`;
3. the vault's engagement rules: the worker leases requests from Phantom
   in small batches through the same gate as local scans, so daily
   budgets, test windows and the emergency stop hold. Unused requests are
   given back when the scan ends.

The network check resolves names on the worker. Pair it with a firewall
or network policy on that machine when the networks must be enforced at
the network level too.

## Limits

- Requests are not recorded in history from an environment.
- A worker that stops reporting for five minutes has its scan failed.
- Schedules run on the workstation; start environment scans by hand.
