---
title: "setNetworkPolicy"
---

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

# setNetworkPolicy

Path: agenthold API › egress

`PUT /agents/{agentId}/network-policy`

URL: `/api/v1/agents/{agentId}/network-policy`

Takes effect within seconds, without a restart.

## Authentication

Requires one of the following:

- `session`, apiKey, in cookie
- `token`, http bearer, header `Authorization`

## Path parameters

- `agentId` (`setNetworkPolicy.path.agentId`; string, required)

## Request body

_Required._

- `mode` (`setNetworkPolicy.mode`; string, required)
  - one of `"open"`, `"allowlist"`
- `allow` (`setNetworkPolicy.allow`; array of string, required) — Entries like "github.com", "*.npmjs.org", "github.com:22", "host:*", "1.2.3.0/24:443". Without a port: 80 and 443.

## Example request

```json
{
  "mode": "open",
  "allow": [
    "string"
  ]
}
```

## Code samples

### cURL

```bash
curl --request PUT \
  --url '<base-url>/api/v1/agents/<agentId>/network-policy' \
  --header 'Content-Type: application/json' \
  --cookie 'agenthold_session=<agenthold_session>' \
  --data '
{
  "mode": "open",
  "allow": [
    "string"
  ]
}
'
```

### TypeScript

```typescript
const url = '<base-url>/api/v1/agents/<agentId>/network-policy';
const options = {
  method: 'PUT',
  headers: {
    'Content-Type': 'application/json',
    cookie: 'agenthold_session=<agenthold_session>'
  },
  body: JSON.stringify({mode: 'open', allow: ['string']})
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "<base-url>/api/v1/agents/<agentId>/network-policy"

payload = {
    "mode": "open",
    "allow": ["string"]
}
headers = {
    "cookie": "agenthold_session=<agenthold_session>",
    "Content-Type": "application/json"
}

response = requests.put(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 200

Saved.

#### Example

```json
{
  "mode": "open",
  "allow": [
    "string"
  ]
}
```

- `mode` (`setNetworkPolicy.response.200.mode`; string, required)
  - one of `"open"`, `"allowlist"`
- `allow` (`setNetworkPolicy.response.200.allow`; array of string, required) — Entries like "github.com", "*.npmjs.org", "github.com:22", "host:*", "1.2.3.0/24:443". Without a port: 80 and 443.

### 400

Error.

#### Example

```json
{
  "error": "string"
}
```

- `error` (`setNetworkPolicy.response.400.error`; string, required)

### 403

Error.

#### Example

```json
{
  "error": "string"
}
```

- `error` (`setNetworkPolicy.response.403.error`; string, required)

### 404

Error.

#### Example

```json
{
  "error": "string"
}
```

- `error` (`setNetworkPolicy.response.404.error`; string, required)


Source: https://agenthold.dev/api/set-network-policy/index.md
