---
title: "Create a network policy"
---

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

# Create a network policy

Path: CloudRaker Workspace API › Network policies

`POST /network-policies`

Creates an immutable policy: the set of hosts an agent version carrying it may reach, the connection whose credential is injected per host, and whether a request to a host parks as a human approval first. Model traffic is NOT egress: the sandbox loop calls the platform model relay, which runs the call on the platform’s own inference binding, so the platform’s own model host is refused as a policy host. Authorization: org admin.

## Authentication

- `bearerAuth`, http, header `Authorization`

## Request body

_Required._

- `name` (`createNetworkPolicy.name`; string, required)
  - minLength 1; maxLength 200
- `hosts` (`createNetworkPolicy.hosts`; map<object>, required) — Host → rule. A key is an exact lowercase public DNS hostname: no port, no wildcard, no path, no IP literal, no internal or private target. At most 50.

## Example request

```json
{
  "name": "string",
  "hosts": {
    "property1": {
      "credentialRef": "string",
      "approval": false
    },
    "property2": {
      "credentialRef": "string",
      "approval": false
    }
  }
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url https://api.cloudraker.com/network-policies \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "name": "string",
  "hosts": {
    "property1": {
      "credentialRef": "string",
      "approval": false
    },
    "property2": {
      "credentialRef": "string",
      "approval": false
    }
  }
}
'
```

### TypeScript

```typescript
const url = 'https://api.cloudraker.com/network-policies';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({
    name: 'string',
    hosts: {
      property1: {credentialRef: 'string', approval: false},
      property2: {credentialRef: 'string', approval: false}
    }
  })
};

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

### Python

```python
import requests

url = "https://api.cloudraker.com/network-policies"

payload = {
    "name": "string",
    "hosts": {
        "property1": {
            "credentialRef": "string",
            "approval": False
        },
        "property2": {
            "credentialRef": "string",
            "approval": False
        }
    }
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

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

print(response.text)
```

## Responses

### 201

The new policy.

#### Example

```json
{
  "data": {
    "id": "string",
    "name": "string",
    "hosts": {
      "property1": {
        "credentialRef": "string",
        "approval": true
      },
      "property2": {
        "credentialRef": "string",
        "approval": true
      }
    },
    "createdAt": "2019-08-24T14:15:22Z",
    "createdBy": "string",
    "revokedAt": "2019-08-24T14:15:22Z"
  }
}
```

- `data` (`createNetworkPolicy.response.201.data`; object, required)
  - `id` (`createNetworkPolicy.response.201.data.id`; string, required)
    - pattern `^net_[0-9A-HJKMNP-TV-Z]{26}$`
  - `name` (`createNetworkPolicy.response.201.data.name`; string, required)
  - `hosts` (`createNetworkPolicy.response.201.data.hosts`; map<object>, required)
  - `createdAt` (`createNetworkPolicy.response.201.data.createdAt`; string, required)
    - format `date-time`; pattern `^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z))$`
  - `createdBy` (`createNetworkPolicy.response.201.data.createdBy`; string, required)
  - `revokedAt` (`createNetworkPolicy.response.201.data.revokedAt`; any of, required) — Set once the policy is revoked. A revoked policy stays READABLE for history and every egress request under it is denied.
    - any of: `string`, `null`

### 400

Validation Error

#### Example

```json
{
  "success": false,
  "error": [
    null
  ],
  "data": null
}
```

- `success` (`createNetworkPolicy.response.400.success`; boolean, required)
  - one of `false`
- `error` (`createNetworkPolicy.response.400.error`; array<unknown>, required)
- `data` (`createNetworkPolicy.response.400.data`; unknown, required)

### 403

`forbidden` — writing a network policy is an org-admin action.

#### Example

```json
{
  "error": "string",
  "error_code": "string",
  "issues": [
    {
      "path": "string",
      "code": "string",
      "message": "string"
    }
  ]
}
```

- `error` (`createNetworkPolicy.response.403.error`; string, required) — The sentence a human reads.
- `error_code` (`createNetworkPolicy.response.403.error_code`; string, required) — The stable snake_case branch key.
- `issues` (`createNetworkPolicy.response.403.issues`; array<object>, optional) — Per-field detail, present only on a validation failure.
  - `path` (`createNetworkPolicy.response.403.issues.path`; string, required)
  - `code` (`createNetworkPolicy.response.403.issues.code`; string, required)
  - `message` (`createNetworkPolicy.response.403.issues.message`; string, required)

### 422

`invalid_network_policy` — a host is not an exact public DNS name, or the policy lists more than 50 of them. The sentence names the offending host.

#### Example

```json
{
  "error": "string",
  "error_code": "string",
  "issues": [
    {
      "path": "string",
      "code": "string",
      "message": "string"
    }
  ]
}
```

- `error` (`createNetworkPolicy.response.422.error`; string, required) — The sentence a human reads.
- `error_code` (`createNetworkPolicy.response.422.error_code`; string, required) — The stable snake_case branch key.
- `issues` (`createNetworkPolicy.response.422.issues`; array<object>, optional) — Per-field detail, present only on a validation failure.
  - `path` (`createNetworkPolicy.response.422.issues.path`; string, required)
  - `code` (`createNetworkPolicy.response.422.issues.code`; string, required)
  - `message` (`createNetworkPolicy.response.422.issues.message`; string, required)


Source: https://docs.cloudraker.com/workspace/api/network-policies/create-network-policy/index.md
