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

# Set a network policy

> Replace what a sandbox may connect to: everything, nothing, a list of domains and IP ranges, or the policy of its environment. Same as boat network set.



## OpenAPI

````yaml openapi/boat-v1.yaml PUT /sandboxes/{sandboxId}/network
openapi: 3.1.0
info:
  title: Boat Public API v1
  version: 1.0.0
  description: >
    Public JSON API for creating, operating, prompting, observing, and exposing
    sandboxes from backend services, CI jobs, hosted workers, and Boat
    automation products.


    The v1 reference intentionally documents the developer integration surface
    only. Dashboard billing actions are not part of v1.
servers:
  - url: https://boat.dev/api/v1
security:
  - BoatBearerAuth: []
tags:
  - name: Boat
    description: >-
      Unified Boat account, setup, lifecycle, prompting, event history, desktop
      access, and SSH operations.
paths:
  /sandboxes/{sandboxId}/network:
    put:
      tags:
        - Boat
      summary: Replace a sandbox's network policy
      description: >-
        Replaces the whole outbound policy, on a running or a stopped sandbox. A
        change also ends open connections that the new policy does not allow.
        Commands, SSH and files keep working. Hosted ports and the desktop stop
        working in `deny` and `allow`, because their tunnel is an outbound
        connection. Needs `network.write`, which only the `admin` preset holds.
        The key inside a sandbox is always refused.
      operationId: setNetworkPolicy
      parameters:
        - $ref: '#/components/parameters/SandboxId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NetworkPolicyRequest'
      responses:
        '200':
          description: >-
            Enforced now, or saved on a stopped sandbox and applied before its
            next start (`status` is then `pending`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NetworkPolicyResponse'
              examples:
                enforced:
                  value:
                    ok: true
                    type: network.updated
                    network:
                      mode: deny
                      allow: []
                      status: enforced
                      updatedAt: '2026-11-23T12:00:00Z'
        '202':
          description: >-
            Saved. The sandbox runs and the policy is not fully on its host yet;
            boat retries until it is. Read `status` again.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NetworkPolicyResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
components:
  parameters:
    SandboxId:
      name: sandboxId
      in: path
      required: true
      schema:
        type: string
        pattern: ^bx_[23456789abcdefghjkmnpqrstuvwxyz]{8}$
      description: Public Sandbox id returned by create/list/get sandbox calls.
  schemas:
    NetworkPolicyRequest:
      type: object
      description: >-
        What the sandbox may connect to. Send `mode`, `inbound` or both: at
        least one. The side that the request does not name stays as it is. A
        sandbox that sets one side has its own policy and no longer follows its
        environment; `mode: environment` makes it follow again. On create,
        omitted means the policy of its environment; with `from`, the policy
        that the saved snapshot's sandbox had. On fork, omitted means what the
        source sandbox has. An API key without the `network.write` action always
        gets the policy that the sandbox would have without this field, a
        tighter one included: any other value is refused with 403
        `api_key_action_forbidden`. A bad policy is refused with 400
        `invalid_network_policy`. When no host can enforce a policy now, create
        and fork answer 409 `network_policy_unsupported`. A CI runner is always
        `open` and follows no environment.
      additionalProperties: false
      properties:
        mode:
          type: string
          enum:
            - open
            - deny
            - allow
            - environment
          description: >-
            `open`: no limit. `deny`: the sandbox opens no connection. `allow`:
            it connects only to the entries of `allow`. `environment`: no policy
            of its own; the sandbox follows the policy of its environment (open
            when the environment sets none). This is the default on create. In
            an organization environment that sets a policy, only owners and
            admins can give a sandbox another policy: members get 403
            `network_policy_managed`.
        allow:
          type: array
          maxItems: 100
          items:
            type: string
          description: >-
            With mode `allow`, 1 to 100 entries; empty or omitted with any other
            mode. Each entry is a domain (`github.com`), a wildcard
            (`*.github.com`, which covers the domain itself and every
            subdomain), a public IP address or a public CIDR range. No scheme,
            port or path. A domain entry allows TCP 443 (matched by TLS SNI) and
            TCP 80 (matched by HTTP Host). An IP or CIDR entry allows every
            protocol and port.
          examples:
            - - github.com
              - '*.githubusercontent.com'
              - 192.0.43.0/24
        inbound:
          type: string
          enum:
            - open
            - boat-only
          description: >-
            Who can connect to the sandbox. `open`: anyone on the internet, on
            the ports that the sandbox opens. `boat-only`: only boat. The host
            drops every other connection to the sandbox, so code inside cannot
            make a port public. SSH, editors, port forwards, the desktop and raw
            ports stop: their routes answer 403 `inbound_closed`. A caller
            outside the sandbox (a session, or an API key that does not live in
            a sandbox) can still publish a port with `POST
            /sandboxes/{id}/host`. Commands and files through the API keep
            working. Omitted on PUT: the sandbox keeps what it has. Omitted on
            create or fork: what the sandbox inherits, else `open`. A change of
            `inbound` is a change of the policy: the same rules on keys and on
            organization environments apply.
      examples:
        - mode: deny
        - mode: deny
          inbound: boat-only
        - inbound: boat-only
        - mode: allow
          allow:
            - github.com
            - registry.npmjs.org
        - mode: environment
    NetworkPolicyResponse:
      allOf:
        - $ref: '#/components/schemas/SuccessBase'
        - type: object
          required:
            - network
          properties:
            type:
              type: string
              enum:
                - network.info
                - network.updated
            network:
              $ref: '#/components/schemas/SandboxNetwork'
            sandbox:
              type: object
              description: The sandbox of this policy and its state now.
              properties:
                id:
                  type: string
                state:
                  type:
                    - string
                    - 'null'
                  description: The sandbox state, as in the sandbox object.
    SuccessBase:
      type: object
      required:
        - ok
        - type
      properties:
        ok:
          type: boolean
          examples:
            - true
        type:
          type: string
          description: Stable success envelope discriminator added by v1.
    SandboxNetwork:
      type: object
      description: The sandbox's outbound network policy.
      required:
        - mode
        - allow
        - status
        - updatedAt
      properties:
        mode:
          type: string
          enum:
            - open
            - deny
            - allow
        allow:
          type: array
          items:
            type: string
          description: The canonical entries. Empty unless mode is `allow`.
        status:
          type: string
          enum:
            - enforced
            - pending
            - none
          description: >-
            `enforced`: the sandbox's host confirmed this policy. `pending`:
            saved, and not on the host yet. A running sandbox keeps its previous
            rules until then; a stopped one gets this policy before its next
            start. `none`: the mode is `open`.
        inbound:
          type: string
          enum:
            - open
            - boat-only
          description: >-
            Who can connect to the sandbox. `open`: anyone on the internet.
            `boat-only`: only boat; the host drops every other connection to the
            sandbox. `status` covers both directions.
        pendingReason:
          type: string
          enum:
            - host
            - transfer
          description: >-
            Only with status `pending`. `host`: the host has not confirmed the
            policy yet. `transfer`: the host enforces the policy, and a restore
            or a snapshot still runs. Until it ends, the storage servers of boat
            stay reachable over TLS.
        apiBound:
          type:
            - boolean
            - 'null'
          description: >-
            True when this sandbox reaches the boat API only as itself, with the
            credentials boat put in it. boat refuses every other key, sign-in or
            session from inside it with 403 `sandbox_bound`. Every sandbox that
            starts restricted is bound. False on a running sandbox that you
            restricted while it ran: its next start binds it. Null while the
            sandbox has no machine, or while boat prepares one.
        source:
          type: string
          enum:
            - environment
            - sandbox
            - default
          description: >-
            Where the policy comes from. `environment`: the policy of its
            environment version. `sandbox`: a policy set on this sandbox.
            `default`: neither sets one, so the sandbox is open.
        updatedAt:
          type:
            - string
            - 'null'
          format: date-time
          description: When the policy was last set, or null if never.
    ErrorEnvelope:
      type: object
      required:
        - ok
        - type
        - status
        - code
        - message
        - error
        - requestId
      properties:
        ok:
          type: boolean
          examples:
            - false
        type:
          type: string
          examples:
            - sandbox.error
        status:
          type: integer
          examples:
            - 409
        code:
          type: string
          examples:
            - provider_not_configured
        message:
          type: string
          examples:
            - Prompting is locked until Codex is configured on the Agents page.
        requestId:
          type: string
          examples:
            - req_01HX...
        error:
          type: object
          required:
            - code
            - message
            - status
          properties:
            code:
              type: string
            message:
              type: string
            status:
              type: integer
            details:
              type: object
              additionalProperties: true
  responses:
    BadRequest:
      description: Invalid request body or parameters.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
          examples:
            invalid:
              value:
                ok: false
                type: sandbox.error
                status: 400
                code: invalid_json
                message: Request body must be valid JSON.
                error:
                  code: invalid_json
                  message: Request body must be valid JSON.
                  status: 400
                requestId: req_01HX...
    Unauthorized:
      description: Missing or invalid bearer token.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
          examples:
            unauthorized:
              value:
                ok: false
                type: sandbox.error
                status: 401
                code: unauthorized
                message: Unauthorized
                error:
                  code: unauthorized
                  message: Unauthorized
                  status: 401
                requestId: req_01HX...
    Forbidden:
      description: >-
        Authenticated token is not allowed to perform this action.
        `sandbox_bound` on any route means that the call comes from inside a
        sandbox that started with a network policy, with a credential that is
        not its own. `inbound_closed` means that the sandbox accepts connections
        from boat only (`network.inbound` is `boat-only`), so the route cannot
        open a way in: SSH keys, port forwards, the desktop and the browser
        stream. On the host and rotate routes it means that the caller is inside
        a sandbox: the key that lives in a sandbox, or a request that a sandbox
        with a network policy sent. Publish from outside the sandbox.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
          examples:
            sandboxBound:
              value:
                ok: false
                type: sandbox.error
                status: 403
                code: sandbox_bound
                message: >-
                  This sandbox reaches the API only as itself: use the
                  credentials Boat put in it.
                error:
                  code: sandbox_bound
                  message: >-
                    This sandbox reaches the API only as itself: use the
                    credentials Boat put in it.
                  status: 403
                requestId: req_01HX...
            forbidden:
              value:
                ok: false
                type: sandbox.error
                status: 403
                code: forbidden
                message: Forbidden
                error:
                  code: forbidden
                  message: Forbidden
                  status: 403
                requestId: req_01HX...
    NotFound:
      description: Resource not found.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    Conflict:
      description: Request conflicts with current account or sandbox state.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
  securitySchemes:
    BoatBearerAuth:
      type: http
      scheme: bearer
      bearerFormat: sandbox_api_key
      description: >-
        Boat bearer token in the form `boat_...`. Service API keys authenticate
        sandbox operations.

````

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