> ## 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.

# Run untrusted code

> Set up sandboxes for code that you do not trust: no secrets inside, no connection out, no port open to the internet, and results through boat.

Make this setup one time, on an environment.

| The code cannot | Because of |
| - | - |
| Read your secrets | Safe for third parties |
| Call out to the internet | Outbound `deny` |
| Open a port to the internet | Inbound `boat-only` |
| Use the boat API with another key | Automatic, with `deny` or `allow` |

**1. Make the environment**

```bash theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
boat env new untrusted
boat env set untrusted --safe-for-third-parties true --network deny --inbound boat-only
```

To allow some hosts, use `--network allow --allow <entry>`. Read [Outbound](https://docs.boat.dev/network-policy/outbound.md).

**2. Start each sandbox in it, from your server**

```bash CLI theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
boat new --environment untrusted
```

```bash curl theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
curl -sS -X POST "https://boat.dev/api/v1/sandboxes" \
  -H "Authorization: Bearer $BOAT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"ttlSeconds":3600,"environment":"untrusted"}'
```

Check it with `boat network get <id>`:

```text theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
network: deny (no outbound connection)
status:  enforced
source:  environment
inbound: boat only (nothing on the internet can connect)
api:     bound (the sandbox reaches the boat API only as itself)
```

**3. Run the code and get the results through boat**

```bash theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
boat exec bx_f7k2q9hd -- python job.py
```

SSH and the desktop do not work on these sandboxes. Use `boat exec` and the [file API](https://docs.boat.dev/ssh-access.md#copy-files).

## Show a port of such a sandbox

Only you can publish a port, from outside the sandbox. Code inside cannot.

```bash theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
boat host bx_f7k2q9hd 3000
```

A published URL does not work with outbound `deny` or `allow` today. For a sandbox that must show a port, use outbound `open` with inbound `boat-only`. Read [Publish a port](https://docs.boat.dev/network-policy/inbound.md#publish-a-port).

## Keys

* Keep your account API key on your server. Never put it in the sandbox.
* To give a person or a program access to one sandbox, create [a key for one sandbox](https://docs.boat.dev/api-keys/create-and-list.md#a-key-for-one-sandbox).

> [!WARNING]
>
> A policy does not stop every leak. Read the [limits](https://docs.boat.dev/network-policy/reference.md#limits) before you rely on it.


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