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

# Calls between sandboxes

> Call a port of another sandbox of your account by name, with no public URL.

One sandbox calls a port of another sandbox of the same account by name: no exposed port and no API key inside either sandbox.

## Name a sandbox

Create a sandbox with `metadata["styne.name"]` (1 to 63 lowercase letters, digits or inner dashes). The name points at
that sandbox until it ends; a create that asks for a name a live sandbox of your account holds answers
`409 name_taken`, and once the holder is gone the next create takes the name. `GET /names` lists your names. Names
belong to your account: another account can use the same name and never reaches yours.

```bash theme={"theme":"css-variables"}
curl -sS -X POST https://api.styne.ai/sandboxes -H "Authorization: Bearer $STYNE_API_KEY" -H "content-type: application/json" \
  -d '{"templateID": "base", "metadata": {"styne.name": "db"}}'
```

## Call a port by name

```text theme={"theme":"css-variables"}
ANY https://api.styne.ai/call/{name}/{port}/{path}?{query}
```

The request (method, path, query, headers and body) goes to `http://localhost:{port}/{path}` inside the named sandbox, and
its answer comes back as the sandbox sent it. From inside a sandbox, authenticate with the sandbox's own token:

```text theme={"theme":"css-variables"}
curl -sS "$STYNE_API_URL/call/db/8080/rows?limit=5" -H "Authorization: Bearer $STYNE_SANDBOX_TOKEN"
```

An API key works the same from outside. `{name}` may also be the id of a sandbox of your account.

What the called sandbox sees:

| Header | Value |
| - | - |
| `styne-caller` | The calling sandbox's id, or `key` for a call made with an API key |
| `styne-caller-name` | The calling sandbox's name, when it has one |

Both are set by the API, never taken from the request, so the called service can trust them. The caller's
`Authorization` header is removed before the request reaches the sandbox.

A paused sandbox that wakes on traffic is resumed by the call. Answers of the API itself:

| Status | Code | When |
| - | - | - |
| `404` | `not_found` | No sandbox of your account holds the name (also for another account's sandbox) |
| `409` | `sandbox_paused` | The sandbox is paused and does not resume on traffic |
| `410` | `sandbox_ended` | The sandbox has ended |
| `502` | `upstream_unreachable` | Nothing listens on the port |
| `504` | `upstream_timeout` | The port did not answer within 120 seconds |

For WebSocket upgrades use an [exposed port](https://docs.styne.ai/ports.md).

## Operations

| Method | Path | What it does |
| - | - | - |
| `GET` | `/names` | List the account's sandbox names |


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