import Runloop from '@runloop/api-client';
const client = new Runloop({
bearerToken: process.env['RUNLOOP_API_KEY'], // This is the default and can be omitted
});
const networkPolicyView = await client.networkPolicies.create({ name: 'name' });
console.log(networkPolicyView.id);import os
from runloop_api_client import Runloop
client = Runloop(
bearer_token=os.environ.get("RUNLOOP_API_KEY"), # This is the default and can be omitted
)
network_policy_view = client.network_policies.create(
name="name",
)
print(network_policy_view.id)curl --request POST \
--url https://api.runloop.ai/v1/network-policies \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"description": "<string>",
"allow_all": true,
"allow_devbox_to_devbox": true,
"allowed_hostnames": [
"<string>"
],
"allowed_cidrs": [
{
"cidr": "<string>",
"ports": [
{
"port": 123,
"end_port": 123
}
]
}
],
"allow_agent_gateway": true,
"allow_mcp_gateway": true,
"allow_runloop_mirrors": true
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.runloop.ai/v1/network-policies",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => '<string>',
'description' => '<string>',
'allow_all' => true,
'allow_devbox_to_devbox' => true,
'allowed_hostnames' => [
'<string>'
],
'allowed_cidrs' => [
[
'cidr' => '<string>',
'ports' => [
[
'port' => 123,
'end_port' => 123
]
]
]
],
'allow_agent_gateway' => true,
'allow_mcp_gateway' => true,
'allow_runloop_mirrors' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.runloop.ai/v1/network-policies"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"allow_all\": true,\n \"allow_devbox_to_devbox\": true,\n \"allowed_hostnames\": [\n \"<string>\"\n ],\n \"allowed_cidrs\": [\n {\n \"cidr\": \"<string>\",\n \"ports\": [\n {\n \"port\": 123,\n \"end_port\": 123\n }\n ]\n }\n ],\n \"allow_agent_gateway\": true,\n \"allow_mcp_gateway\": true,\n \"allow_runloop_mirrors\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.runloop.ai/v1/network-policies")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"allow_all\": true,\n \"allow_devbox_to_devbox\": true,\n \"allowed_hostnames\": [\n \"<string>\"\n ],\n \"allowed_cidrs\": [\n {\n \"cidr\": \"<string>\",\n \"ports\": [\n {\n \"port\": 123,\n \"end_port\": 123\n }\n ]\n }\n ],\n \"allow_agent_gateway\": true,\n \"allow_mcp_gateway\": true,\n \"allow_runloop_mirrors\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.runloop.ai/v1/network-policies")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"allow_all\": true,\n \"allow_devbox_to_devbox\": true,\n \"allowed_hostnames\": [\n \"<string>\"\n ],\n \"allowed_cidrs\": [\n {\n \"cidr\": \"<string>\",\n \"ports\": [\n {\n \"port\": 123,\n \"end_port\": 123\n }\n ]\n }\n ],\n \"allow_agent_gateway\": true,\n \"allow_mcp_gateway\": true,\n \"allow_runloop_mirrors\": true\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"name": "<string>",
"egress": {
"allow_all": true,
"allow_devbox_to_devbox": true,
"allowed_hostnames": [
"<string>"
],
"allowed_cidrs": [
{
"cidr": "<string>",
"ports": [
{
"port": 123,
"end_port": 123,
"protocol": "TCP"
}
]
}
],
"allow_agent_gateway": true,
"allow_mcp_gateway": true,
"allow_runloop_mirrors": true
},
"create_time_ms": 123,
"update_time_ms": 123,
"description": "<string>"
}Create a NetworkPolicy.
Create a new NetworkPolicy with the specified egress rules. The policy can then be applied to blueprints, devboxes, or snapshot resumes.
import Runloop from '@runloop/api-client';
const client = new Runloop({
bearerToken: process.env['RUNLOOP_API_KEY'], // This is the default and can be omitted
});
const networkPolicyView = await client.networkPolicies.create({ name: 'name' });
console.log(networkPolicyView.id);import os
from runloop_api_client import Runloop
client = Runloop(
bearer_token=os.environ.get("RUNLOOP_API_KEY"), # This is the default and can be omitted
)
network_policy_view = client.network_policies.create(
name="name",
)
print(network_policy_view.id)curl --request POST \
--url https://api.runloop.ai/v1/network-policies \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"description": "<string>",
"allow_all": true,
"allow_devbox_to_devbox": true,
"allowed_hostnames": [
"<string>"
],
"allowed_cidrs": [
{
"cidr": "<string>",
"ports": [
{
"port": 123,
"end_port": 123
}
]
}
],
"allow_agent_gateway": true,
"allow_mcp_gateway": true,
"allow_runloop_mirrors": true
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.runloop.ai/v1/network-policies",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => '<string>',
'description' => '<string>',
'allow_all' => true,
'allow_devbox_to_devbox' => true,
'allowed_hostnames' => [
'<string>'
],
'allowed_cidrs' => [
[
'cidr' => '<string>',
'ports' => [
[
'port' => 123,
'end_port' => 123
]
]
]
],
'allow_agent_gateway' => true,
'allow_mcp_gateway' => true,
'allow_runloop_mirrors' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.runloop.ai/v1/network-policies"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"allow_all\": true,\n \"allow_devbox_to_devbox\": true,\n \"allowed_hostnames\": [\n \"<string>\"\n ],\n \"allowed_cidrs\": [\n {\n \"cidr\": \"<string>\",\n \"ports\": [\n {\n \"port\": 123,\n \"end_port\": 123\n }\n ]\n }\n ],\n \"allow_agent_gateway\": true,\n \"allow_mcp_gateway\": true,\n \"allow_runloop_mirrors\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.runloop.ai/v1/network-policies")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"allow_all\": true,\n \"allow_devbox_to_devbox\": true,\n \"allowed_hostnames\": [\n \"<string>\"\n ],\n \"allowed_cidrs\": [\n {\n \"cidr\": \"<string>\",\n \"ports\": [\n {\n \"port\": 123,\n \"end_port\": 123\n }\n ]\n }\n ],\n \"allow_agent_gateway\": true,\n \"allow_mcp_gateway\": true,\n \"allow_runloop_mirrors\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.runloop.ai/v1/network-policies")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"description\": \"<string>\",\n \"allow_all\": true,\n \"allow_devbox_to_devbox\": true,\n \"allowed_hostnames\": [\n \"<string>\"\n ],\n \"allowed_cidrs\": [\n {\n \"cidr\": \"<string>\",\n \"ports\": [\n {\n \"port\": 123,\n \"end_port\": 123\n }\n ]\n }\n ],\n \"allow_agent_gateway\": true,\n \"allow_mcp_gateway\": true,\n \"allow_runloop_mirrors\": true\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"name": "<string>",
"egress": {
"allow_all": true,
"allow_devbox_to_devbox": true,
"allowed_hostnames": [
"<string>"
],
"allowed_cidrs": [
{
"cidr": "<string>",
"ports": [
{
"port": 123,
"end_port": 123,
"protocol": "TCP"
}
]
}
],
"allow_agent_gateway": true,
"allow_mcp_gateway": true,
"allow_runloop_mirrors": true
},
"create_time_ms": 123,
"update_time_ms": 123,
"description": "<string>"
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
Parameters required to create a new NetworkPolicy.
The human-readable name for the NetworkPolicy. Must be unique within the account.
Optional description for the NetworkPolicy.
(Optional) If true, all egress traffic is allowed (ALLOW_ALL policy). Defaults to false.
(Optional) If true, allows traffic between the account's own devboxes via tunnels. Defaults to false. If allow_all is true, this is automatically set to true.
(Optional) DNS-based allow list with wildcard support. Examples: ['github.com', '*.npmjs.org'].
(Optional) IPv4 CIDR-based allow list with optional port restrictions, additive with allowed_hostnames. Example: [{'cidr': '10.12.0.0/16', 'ports': [{'port': 443}]}].
Show child attributes
Show child attributes
(Optional) If true, allows devbox egress to the agent gateway for credential proxying. Defaults to false.
(Optional) If true, allows devbox egress to the MCP hub for MCP server access. Defaults to false.
(Optional) If true, allows devbox egress to Runloop's package/image registry mirrors. Defaults to false. Implicitly allowed when allow_all is true.
Response
NetworkPolicy created successfully.
A NetworkPolicy defines egress network access rules for devboxes. Policies can be applied to blueprints, devboxes, and snapshot resumes.
The unique identifier of the NetworkPolicy.
The human-readable name of the NetworkPolicy. Unique per account.
The egress rules for this policy.
Show child attributes
Show child attributes
The creation time of the NetworkPolicy (Unix timestamp in milliseconds).
Last update time of the NetworkPolicy (Unix timestamp in milliseconds).
Optional description of the NetworkPolicy.
Was this page helpful?
