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

# Internettoegang

export const SandboxConfigHint = () => {
  if (typeof document === "undefined") {
    return null;
  } else {
    return <Note>Before running the example code in this document, please ensure you have properly configured environment variables. For details, please refer to <a href="/docs/nl/guides/sandbox-your-first-agent-sandbox#configure-environment-variables">Configure Environment Variables</a>.</Note>;
  }
};

Internetconnectiviteit is beschikbaar in elke sandbox, en externe toegang wordt geboden via een openbare URL.

<SandboxConfigHint />

## Internettoegang in- en uitschakelen

Wanneer je een sandbox maakt, kun je de parameter `allowInternetAccess` / `allow_internet_access` gebruiken om internetconnectiviteit te configureren. Internettoegang is standaard ingeschakeld, maar kan worden uitgeschakeld voor workloads met strengere beveiligingseisen.

<CodeGroup>
  ```js JavaScript & TypeScript icon="js" theme={"system"}
  import { Sandbox } from 'novita-sandbox/code-interpreter'

  // Create sandbox with internet access enabled (default)
  const sandbox = await Sandbox.create({ allowInternetAccess: true })

  // Create sandbox without internet access
  const isolatedSandbox = await Sandbox.create({ allowInternetAccess: false })
  ```

  ```python Python icon="python" theme={"system"}
  from novita_sandbox.code_interpreter import Sandbox

  # Create sandbox with internet access enabled (default)
  sandbox = Sandbox.create(allow_internet_access=True)

  # Create sandbox without internet access
  isolated_sandbox = Sandbox.create(allow_internet_access=False)
  ```
</CodeGroup>

Als internettoegang is uitgeschakeld, wordt voorkomen dat de sandbox uitgaande netwerkverzoeken initieert. Dit helpt een extra beschermingslaag toe te voegen bij het uitvoeren van gevoelige code.

<Note>
  Het doorgeven van een falsy-waarde aan `allowInternetAccess` / `allow_internet_access` heeft hetzelfde effect als het toevoegen van `['0.0.0.0/0']` aan `network.denyOut` / `network.deny_out`, wat elke bestemming blokkeert.
</Note>

## Fijnmazige netwerkcontrole

Netwerkconfiguratie biedt fijnmazigere controle over uitgaand verkeer door je allowlists en denylists te laten definiëren.

### Allow- en deny-lijsten

IP-adressen, CIDR-blokken of domeinnamen waartoe de sandbox toegang mag hebben, kunnen worden opgegeven.

<CodeGroup>
  ```js JavaScript & TypeScript icon="js" theme={"system"}
  import { Sandbox } from 'novita-sandbox/code-interpreter'

  // Deny all traffic except specific IPs
  const sandbox = await Sandbox.create({
    network: {
      denyOut: ['0.0.0.0/0'],
      allowOut: ['1.1.1.1', '8.8.8.0/24']
    }
  })

  // Deny specific IPs only
  const restrictedSandbox = await Sandbox.create({
    network: {
      denyOut: ['8.8.8.8']
    }
  })
  ```

  ```python Python icon="python" theme={"system"}
  from novita_sandbox.code_interpreter import Sandbox

  # Deny all traffic except specific IPs
  sandbox = Sandbox.create(
      network={
          "deny_out": ["0.0.0.0/0"],
          "allow_out": ["1.1.1.1", "8.8.8.0/24"]
      }
  )

  # Deny specific IPs only
  restricted_sandbox = Sandbox.create(
      network={
          "deny_out": ["8.8.8.8"]
      }
  )
  ```
</CodeGroup>

<Note>
  De CIDR `'0.0.0.0/0'` / `"0.0.0.0/0"` is een verkorte notatie voor "elke bestemming". Een geëxporteerde constante `ALL_TRAFFIC` wordt herleid tot dezelfde waarde `0.0.0.0/0` als je een benoemd alternatief voor de letterlijke waarde prefereert.
</Note>

### Filteren op basis van domein

Je kunt hostnamen opgeven in `allowOut` / `allow_out` om uitgaand verkeer naar geselecteerde domeinen toe te staan. Wanneer filteren op basis van domein is ingeschakeld, moet al het overige verkeer worden geblokkeerd via `denyOut` / `deny_out`. Domeinvermeldingen worden alleen ondersteund in allow-lijsten en kunnen niet worden gebruikt in deny-lijsten.

<CodeGroup>
  ```js JavaScript & TypeScript icon="js" theme={"system"}
  import { Sandbox } from 'novita-sandbox/code-interpreter'

  // Allow only traffic to google.com
  const sandbox = await Sandbox.create({
    network: {
      allowOut: ['google.com'],
      denyOut: ['0.0.0.0/0']
    }
  })
  ```

  ```python Python icon="python" theme={"system"}
  from novita_sandbox.code_interpreter import Sandbox

  # Allow only traffic to google.com
  sandbox = Sandbox.create(
      network={
          "allow_out": ["google.com"],
          "deny_out": ["0.0.0.0/0"]
      }
  )
  ```
</CodeGroup>

<Note>
  Wanneer er een domein in de configuratie voorkomt, wordt de standaardnameserver `8.8.8.8` automatisch toegestaan, zodat DNS-resolutie blijft werken.
</Note>

Je kunt ook elk subdomein van een domein matchen met een wildcard:

<CodeGroup>
  ```js JavaScript & TypeScript icon="js" theme={"system"}
  import { Sandbox } from 'novita-sandbox/code-interpreter'

  // Allow traffic to any subdomain of mydomain.com
  const sandbox = await Sandbox.create({
    network: {
      allowOut: ['*.mydomain.com'],
      denyOut: ['0.0.0.0/0']
    }
  })
  ```

  ```python Python icon="python" theme={"system"}
  from novita_sandbox.code_interpreter import Sandbox

  # Allow traffic to any subdomain of mydomain.com
  sandbox = Sandbox.create(
      network={
          "allow_out": ["*.mydomain.com"],
          "deny_out": ["0.0.0.0/0"]
      }
  )
  ```
</CodeGroup>

Domeinen, IP-adressen en CIDR-bereiken kunnen allemaal samen in dezelfde lijst worden opgenomen:

<CodeGroup>
  ```js JavaScript & TypeScript icon="js" theme={"system"}
  import { Sandbox } from 'novita-sandbox/code-interpreter'

  // Allow traffic to specific domains and IPs
  const sandbox = await Sandbox.create({
    network: {
      allowOut: ['api.example.com', '*.github.com', '8.8.8.8'],
      denyOut: ['0.0.0.0/0']
    }
  })
  ```

  ```python Python icon="python" theme={"system"}
  from novita_sandbox.code_interpreter import Sandbox

  # Allow traffic to specific domains and IPs
  sandbox = Sandbox.create(
      network={
          "allow_out": ["api.example.com", "*.github.com", "8.8.8.8"],
          "deny_out": ["0.0.0.0/0"]
      }
  )
  ```
</CodeGroup>

<Note>
  Filteren op domein is alleen van toepassing op HTTP via poort 80 (geïnspecteerd via de Host-header) en TLS via poort 443 (geïnspecteerd via SNI). Elke andere poort valt terug op matching op basis van CIDR, en UDP-protocollen zoals QUIC/HTTP3 kunnen niet op domein worden gefilterd.
</Note>

### Hoe geblokkeerde TCP-verbindingen zich gedragen

Vanwege de firewallarchitectuur kan een geblokkeerde uitgaande verbinding er vanuit de sandbox nog steeds succesvol uitzien.

De firewall moet eerst de TCP-verbinding accepteren voordat kan worden beoordeeld of de doelbestemming is toegestaan. Daardoor kan code die binnen de sandbox draait zien dat de verbinding slaagt en de socket wordt geopend, zelfs als de bestemming is geblokkeerd. In dat geval wordt er in werkelijkheid geen verkeer afgeleverd bij het externe endpoint.

Om te bevestigen dat de bestemming bereikbaar is, valideer je een respons op applicatieniveau in plaats van alleen te vertrouwen op het slagen van de TCP-verbinding. Controleer bijvoorbeeld op een HTTP-statuscode, een voltooide TLS-handshake of de verwachte responsbytes van het protocol.

Dit gedrag is een huidige beperking van de manier waarop uitgaand sandboxverkeer via onze firewall wordt gerouteerd en kan in de toekomst worden bijgewerkt.

### Prioriteitsregels

Als zowel allow- als deny-regels zijn geconfigureerd, **hebben de allow-regels prioriteit**. Daarom blijft elk IP-adres dat in beide lijsten voorkomt toegestaan.

<CodeGroup>
  ```js JavaScript & TypeScript icon="js" theme={"system"}
  import { Sandbox } from 'novita-sandbox/code-interpreter'

  // Even though all traffic is denied, 1.1.1.1 and 8.8.8.8 are explicitly allowed
  const sandbox = await Sandbox.create({
    network: {
      denyOut: ['0.0.0.0/0'],
      allowOut: ['1.1.1.1', '8.8.8.8']
    }
  })
  ```

  ```python Python icon="python" theme={"system"}
  from novita_sandbox.code_interpreter import Sandbox

  # Even though all traffic is denied, 1.1.1.1 and 8.8.8.8 are explicitly allowed
  sandbox = Sandbox.create(
      network={
          "deny_out": ["0.0.0.0/0"],
          "allow_out": ["1.1.1.1", "8.8.8.8"]
      }
  )
  ```
</CodeGroup>

De instellingen `network` worden alleen van kracht wanneer de sandbox wordt gemaakt — geef ze door aan `Sandbox.create`. Zodra de sandbox bestaat, staan ze vast en kunnen ze niet worden gewijzigd.

## Openbare URL van de sandbox

Services in een sandbox zijn toegankelijk via de openbare URL van de sandbox.

<CodeGroup>
  ```js JavaScript & TypeScript icon="js" theme={"system"}
  import { Sandbox } from 'novita-sandbox/code-interpreter'

  const sandbox = await Sandbox.create()

  // You need to always pass a port number to get the host
  const host = sandbox.getHost(3000)
  console.log(`https://${host}`)
  ```

  ```python Python icon="python" theme={"system"}
  from novita_sandbox.code_interpreter import Sandbox

  sandbox = Sandbox.create()

  # You need to always pass a port number to get the host
  host = sandbox.get_host(3000)
  print(f'https://{host}')
  ```
</CodeGroup>

De uitvoer ziet er als volgt uit:

<CodeGroup>
  ```bash JavaScript & TypeScript icon="terminal" theme={"system"}
  https://3000-i62mff4ahtrdfdkyn2esc.sandbox.novita.ai
  ```

  ```bash Python icon="terminal" theme={"system"}
  https://3000-i62mff4ahtrdfdkyn2esc.sandbox.novita.ai
  ```
</CodeGroup>

Het meest linkse segment van de hostnaam is exact het poortnummer dat je aan de methode hebt doorgegeven.

## Verbinding maken met een server die in de sandbox draait

Je kunt verbinding maken met een server die in de sandbox draait met de eerder beschreven methode; start bijvoorbeeld een lichtgewicht HTTP-server op poort 3000 om bestanden vanuit de startdirectory te serveren.

<CodeGroup>
  ```js JavaScript & TypeScript icon="js" theme={"system"}
  import { Sandbox } from 'novita-sandbox/code-interpreter'

  const sandbox = await Sandbox.create()

  // Start a simple HTTP server inside the sandbox.
  const process = await sandbox.commands.run('python -m http.server 3000', { background: true })
  const host = sandbox.getHost(3000)
  const url = `https://${host}`
  console.log('Server started at:', url)

  // Fetch data from the server inside the sandbox.
  const response = await fetch(url);
  const data = await response.text();
  console.log('Response from server inside sandbox:', data);

  // Kill the server process inside the sandbox.
  await process.kill()
  ```

  ```python Python icon="python" theme={"system"}
  import requests
  from novita_sandbox.code_interpreter import Sandbox

  sandbox = Sandbox.create()

  # Start a simple HTTP server inside the sandbox.
  process = sandbox.commands.run("python -m http.server 3000", background=True)
  host = sandbox.get_host(3000)
  url = f"https://{host}"
  print('Server started at:', url)

  # Fetch data from the server inside the sandbox.
  response = requests.get(url)
  data = response.text
  print('Response from server inside sandbox:', data)

  # Kill the server process inside the sandbox.
  process.kill()
  ```
</CodeGroup>

Deze uitvoer is als volgt:

<CodeGroup>
  ```bash JavaScript & TypeScript icon="terminal" theme={"system"}
  Server started at: https://3000-ip3nfrvajtqu5ktoxugc7.sandbox.novita.ai
  Response from server inside sandbox: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  <html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>Directory listing for /</title>
  </head>
  <body>
  <h1>Directory listing for /</h1>
  <hr>
  <ul>
  <li><a href=".bash_logout">.bash_logout</a></li>
  <li><a href=".bashrc">.bashrc</a></li>
  <li><a href=".profile">.profile</a></li>
  </ul>
  <hr>
  </body>
  </html>
  ```

  ```bash Python icon="terminal" theme={"system"}
  Server started at: https://3000-ip3nfrvajtqu5ktoxugc7.sandbox.novita.ai
  Response from server inside sandbox: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  <html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>Directory listing for /</title>
  </head>
  <body>
  <h1>Directory listing for /</h1>
  <hr>
  <ul>
  <li><a href=".bash_logout">.bash_logout</a></li>
  <li><a href=".bashrc">.bashrc</a></li>
  <li><a href=".profile">.profile</a></li>
  </ul>
  <hr>
  </body>
  </html>
  ```
</CodeGroup>

## Host-headers van aanvragen maskeren

Je kunt de optie `maskRequestHost` / `mask_request_host` gebruiken om de Host-header aan te passen die naar services wordt verzonden die in de sandbox draaien. Dit is handig wanneer je applicatie verwacht dat aanvragen een specifieke hostindeling volgen.

<CodeGroup>
  ```js JavaScript & TypeScript icon="js" theme={"system"}
  import { Sandbox } from 'novita-sandbox/code-interpreter'

  // Create sandbox with custom host masking
  const sandbox = await Sandbox.create({
    network: {
      maskRequestHost: 'localhost:${PORT}'
    }
  })

  // The ${PORT} variable will be replaced with the actual port number
  // Requests to the sandbox will have Host header set to for example: localhost:8080
  ```

  ```python Python icon="python" theme={"system"}
  from novita_sandbox.code_interpreter import Sandbox

  # Create sandbox with custom host masking
  sandbox = Sandbox.create(
      network={
          "mask_request_host": "localhost:${PORT}"
      }
  )

  # The ${PORT} variable will be replaced with the actual port number
  # Requests to the sandbox will have Host header set to for example: localhost:8080
  ```
</CodeGroup>

Op het moment van de aanvraag wordt `${PORT}` in het masker vervangen door het echte poortnummer van de service die wordt aangesproken.
