> ## Documentation Index
> Fetch the complete documentation index at: https://s2.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Network Policies

> Create, list, inspect, and delete network policies with the S2 CLI.

[Network policies](https://s2.dev/docs/concepts/network-policies.md) restrict which networks an access token can be used from.

### Create a network policy

Allow CIDR blocks with `--cidr`, and AWS VPC endpoints with `--aws-vpce`. Both are repeatable, and a request matching any of them is accepted:

```bash theme={null}
s2 network-policy create office --cidr 203.0.113.0/24 --cidr 2001:db8:1234::/48
s2 network-policy create vpc-only --aws-vpce vpce-0a1b2c3d4e5f67890
s2 network-policy create office-or-vpc \
  --cidr 203.0.113.0/24 \
  --aws-vpce vpce-0a1b2c3d4e5f67890
```

Without `--cidr`, tokens bound to the policy cannot be used over the public internet. Without `--aws-vpce`, they cannot be used through PrivateLink.

The full `<slug>.<nonce>` reference of the new policy is printed.

### Issue a token with a network policy

```bash theme={null}
s2 access-token issue office-token --preset read-only --network-policy office
```

### List network policies

```bash theme={null}
s2 network-policy list
```

Use `--prefix` to filter by slug.

### Get a network policy

```bash theme={null}
s2 network-policy get office
```

### Delete a network policy

```bash theme={null}
s2 network-policy delete office
```

A policy cannot be deleted while an access token is bound to it. Revoke those tokens first.

### Denied requests

When a token's network policy rejects a request, the error shows the address S2 saw:

```
Error:   × Failed to list basins: network_policy_denied: Request from 198.51.100.7 is
  │ not permitted by the token's network policy
  ╰─▶ network_policy_denied: Request from 198.51.100.7 is not permitted by the
      token's network policy
  help: The access token is bound to a network policy that does not permit
        requests from this network. Retry from a permitted network, or use a
        token without that restriction.
```

See which addresses a token was accepted and denied from with:

```bash theme={null}
s2 metrics account token-activity office-token
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.