# CreatePort makes one sandbox port reachable outside the sandbox.


[API catalog](/reference/api/) · [Docker Sandboxes overview](/reference/api/sandboxes/latest/) · [Product manual](https://docs.docker.com/ai/sandboxes-api/) · [OpenAPI specification](/reference/api/sandboxes/api.yaml)

API version: v1


> This API is experimental. Features, interfaces,
> and behavior may change.




`POST /v1/sandboxes/{sandbox}/ports`

CreatePort makes one sandbox port reachable outside the sandbox.

## Connection and access

[API connection and authentication guidance](/reference/api/sandboxes/latest/#authentication)


Server: `https://connect.docker.com/sandboxes`

Effective security: alternatives are OR; schemes within an alternative are AND. An empty array declares no HTTP authentication requirement.

```json
[
  {
    "bearer": []
  }
]
```

## Example request

Replace placeholders and provide the required credentials or request body.

```console
curl \
  --request POST \
  --header "Authorization: Bearer ${TOKEN}" \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data-binary @request-body \
  'https://connect.docker.com/sandboxes/v1/sandboxes/<SANDBOX>/ports'
```


Prepare request-body using the selected media type and schema.


## Parameters

### sandbox

Location: path. Required: yes.

The sandbox id.

```json
{
  "description": "The sandbox id.",
  "in": "path",
  "name": "sandbox",
  "pointer": "/paths/~1v1~1sandboxes~1{sandbox}~1ports/post/parameters/0",
  "required": true,
  "schema": {
    "type": "string"
  }
}
```

### Idempotency-Key

Location: header. Required: no.

Replay key. Reusing it with a different payload fails with failedPrecondition; accepted keys are retained for at least 24 hours.

```json
{
  "description": "Replay key. Reusing it with a different payload fails with failedPrecondition; accepted keys are retained for at least 24 hours.",
  "in": "header",
  "name": "Idempotency-Key",
  "pointer": "/paths/~1v1~1sandboxes~1{sandbox}~1ports/post/parameters/1",
  "schema": {
    "description": "Idempotency key. A replay returns the first result; the same key with a different payload fails with FAILED_PRECONDITION; retained at least 24 hours.",
    "title": "Idempotency-Key",
    "type": "string"
  }
}
```

## Request and responses

### Request  application/json




Schema:

```json
{
  "additionalProperties": false,
  "description": "CreatePortRequest publishes one sandbox port.",
  "properties": {
    "port": {
      "$ref": "#/components/schemas/CreatePortRequestPortInput",
      "description": "port is the requested publication."
    }
  },
  "required": [
    "port"
  ],
  "title": "CreatePortRequest",
  "type": "object"
}
```










### Response 201 application/json

Success


Schema:

```json
{
  "$ref": "#/components/schemas/Port"
}
```



Headers:

```json
{
  "ETag": {
    "description": "The etag of the resource this response carries, which the next mutation of it sends as If-Match.",
    "schema": {
      "type": "string"
    }
  }
}
```








### Response 409 application/json

Creation conflicts with an existing resource (ALREADY_EXISTS).

The sandbox already publishes this port number.

The Idempotency-Key was already used with a different payload.


Schema:

```json
{
  "$ref": "#/components/schemas/Error"
}
```









alreadyExists:
```json
{
  "code": "alreadyExists",
  "message": "The sandbox already publishes this port number."
}
```

failedPrecondition:
```json
{
  "code": "failedPrecondition",
  "message": "The Idempotency-Key was already used with a different payload."
}
```


### Response default application/json

The structured Error body identifies the failure with a stable code and optional typed details.


Schema:

```json
{
  "$ref": "#/components/schemas/Error"
}
```









Schema example:
```json
{
  "code": "notFound",
  "details": [],
  "message": "sandbox not found"
}
```


## Complete operation contract

```json
{
  "description": "CreatePort makes one sandbox port reachable outside the sandbox.",
  "operationId": "createPort",
  "parameters": [
    {
      "description": "The sandbox id.",
      "in": "path",
      "name": "sandbox",
      "required": true,
      "schema": {
        "type": "string"
      }
    },
    {
      "description": "Replay key. Reusing it with a different payload fails with failedPrecondition; accepted keys are retained for at least 24 hours.",
      "in": "header",
      "name": "Idempotency-Key",
      "schema": {
        "description": "Idempotency key. A replay returns the first result; the same key with a different payload fails with FAILED_PRECONDITION; retained at least 24 hours.",
        "title": "Idempotency-Key",
        "type": "string"
      }
    }
  ],
  "requestBody": {
    "content": {
      "application/json": {
        "schema": {
          "additionalProperties": false,
          "description": "CreatePortRequest publishes one sandbox port.",
          "properties": {
            "port": {
              "$ref": "#/components/schemas/CreatePortRequestPortInput",
              "description": "port is the requested publication."
            }
          },
          "required": [
            "port"
          ],
          "title": "CreatePortRequest",
          "type": "object"
        }
      }
    },
    "required": true
  },
  "responses": {
    "201": {
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/Port"
          }
        }
      },
      "description": "Success",
      "headers": {
        "ETag": {
          "description": "The etag of the resource this response carries, which the next mutation of it sends as If-Match.",
          "schema": {
            "type": "string"
          }
        }
      }
    },
    "409": {
      "content": {
        "application/json": {
          "examples": {
            "alreadyExists": {
              "summary": "The sandbox already publishes this port number.",
              "value": {
                "code": "alreadyExists",
                "message": "The sandbox already publishes this port number."
              }
            },
            "failedPrecondition": {
              "summary": "The Idempotency-Key was already used with a different payload.",
              "value": {
                "code": "failedPrecondition",
                "message": "The Idempotency-Key was already used with a different payload."
              }
            }
          },
          "schema": {
            "$ref": "#/components/schemas/Error"
          }
        }
      },
      "description": "Creation conflicts with an existing resource (ALREADY_EXISTS).\n\nThe sandbox already publishes this port number.\n\nThe Idempotency-Key was already used with a different payload."
    },
    "default": {
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/Error"
          }
        }
      },
      "description": "The structured Error body identifies the failure with a stable code and optional typed details."
    }
  },
  "security": [
    {
      "bearer": []
    }
  ],
  "summary": "CreatePort makes one sandbox port reachable outside the sandbox.",
  "tags": [
    "Sandboxes"
  ],
  "x-sbx-authenticated-only": false,
  "x-sbx-conditional-permissions": [],
  "x-sbx-error-responses": [
    {
      "code": "ALREADY_EXISTS",
      "description": "The sandbox already publishes this port number."
    },
    {
      "code": "FAILED_PRECONDITION",
      "description": "The Idempotency-Key was already used with a different payload."
    }
  ],
  "x-sbx-plane": "control",
  "x-sbx-required-permissions": [
    "sandboxesPorts"
  ],
  "x-sbx-serving-surface": "management"
}
```

## Referenced schemas

- [#/components/schemas/CreatePortRequestPortInput](/reference/api/sandboxes/latest/schemas/CreatePortRequestPortInput/)

- [#/components/schemas/Error](/reference/api/sandboxes/latest/schemas/Error/)

- [#/components/schemas/Port](/reference/api/sandboxes/latest/schemas/Port/)




