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

> ## Agent Instructions
> Setting OneCLI up for your person? Follow https://onecli.sh/docs/quickstart.md. Never ask for or accept a key, token or password in the chat: OneCLI needs none.
> No OneCLI credential? Run `onecli connect`, or follow https://onecli.sh/auth.md. A person approves every new agent in their browser.
> Already connected? `onecli status`, `onecli items` and `onecli check <METHOD> <URL>` tell you what you can use. Full guide: https://onecli.sh/skill.md
> Search these docs over MCP at https://onecli.sh/docs/mcp. Report a wrong or unclear page with its `submit_feedback` tool.

# Connect an agent in a boat sandbox

> Start a boat sandbox from TypeScript or Python with its own OneCLI agent: the agent's settings, an allow network policy for OneCLI, and no key inside it.

Your code starts a boat sandbox and makes a OneCLI agent for it, on one vault. The sandbox can reach only OneCLI. Its HTTPS calls go through the gateway, which adds the vault's key on the way out, so no key is ever in the sandbox.

## Before you start

* A OneCLI managing key in `ONECLI_API_KEY`. Make one in the dashboard under **Settings** > **API keys**. It stays with your code: never put it in the sandbox.
* A boat API key in `BOAT_API_KEY`, with the actions the example uses. Make one with `boat api-key create my-app --actions sandbox.create,sandbox.read,sandbox.stop,sandbox.delete-own,exec,network.write`: it prints the key once. A key made with `--preset ci` cannot set a network policy, so boat refuses the example with `403`.
* Node.js 22 or later, or Python 3.11 or later.
* The example uses your **Personal** vault and its **Test key** for `httpbin.org`, which every account starts with. Use any vault, and any host it has an item for.

## Install

```bash TypeScript theme={null}
npm install @onecli-sh/sdk @boatdev/sdk
```

```bash Python theme={null}
pip install onecli-sdk boat-sdk
```

## Example

Save the TypeScript as `sandbox.mts` and run `npx tsx sandbox.mts`, or the Python as `sandbox.py` and run `python sandbox.py`. It prints `200`.

```typescript TypeScript theme={null}
import { OneCLI } from "@onecli-sh/sdk";
import {
  BoatApi,
  Configuration,
  execCommand,
  stopAndRemove,
  waitUntilReady,
} from "@boatdev/sdk";

const onecli = new OneCLI(); // reads ONECLI_API_KEY
const boat = new BoatApi(
  new Configuration({
    basePath: "https://boat.dev/api/v1",
    accessToken: process.env.BOAT_API_KEY!,
  }),
);

// 1. An agent on your Personal vault. It ends by itself after an hour.
const agent = await onecli.agents.create({
  vaultName: "Personal",
  provider: "boat",
  ttlSeconds: 3600,
});

// 2. The sandbox: the agent's settings, and a network to OneCLI only.
const created = await boat.create({
  ttlSeconds: 3600,
  noEnv: true, // none of your boat account's stored secrets
  env: agent.env,
  network: { mode: "allow", allow: agent.allowHosts },
});
const id = created.sandbox.id;

// Run one shell line and return what it printed.
const run = async (line: string): Promise<string> => {
  const result = await execCommand(boat, id, line);
  if (!("stdout" in result) || result.exitCode !== 0)
    throw new Error(`failed: ${line}`);
  return result.stdout;
};

try {
  await waitUntilReady(boat, id);

  // 3. Once: write the certificate files that agent.env points at.
  await run(agent.setupCommand);

  // httpbin.org/bearer answers 401 with no key.
  // 200 means the gateway added the Test key.
  const call =
    'curl -s -o /dev/null -w "%{http_code}" https://httpbin.org/bearer';
  console.log(await run(call)); // 200
} finally {
  await stopAndRemove(boat, id, { delete: true });
  await agent.disconnect();
}
```

```python Python theme={null}
import os

from boat_sdk import (
    ApiClient,
    BoatApi,
    CommandResponse,
    Configuration,
    CreateSandboxRequest,
    NetworkPolicyRequest,
)
from boat_sdk.boat_helpers import exec_command, stop_and_remove, wait_until_ready
from onecli import OneCLI

config = Configuration(
    host="https://boat.dev/api/v1",
    access_token=os.environ["BOAT_API_KEY"],
)

with OneCLI() as onecli, ApiClient(config) as client:  # OneCLI reads ONECLI_API_KEY
    boat = BoatApi(client)

    # 1. An agent on your Personal vault. It ends by itself after an hour,
    #    and leaving the block disconnects it.
    with onecli.agents.create(
        vault_name="Personal",
        provider="boat",
        ttl_seconds=3600,
    ) as agent:
        # 2. The sandbox: the agent's settings, and a network to OneCLI only.
        created = boat.create(
            create_sandbox_request=CreateSandboxRequest(
                ttl_seconds=3600,
                no_env=True,  # none of your boat account's stored secrets
                env=agent.env,
                network=NetworkPolicyRequest(mode="allow", allow=agent.allow_hosts),
            )
        )
        sandbox_id = created.sandbox.id

        def run(line: str) -> str:
            """Run one shell line and return what it printed."""
            result = exec_command(boat, sandbox_id, line).actual_instance
            if not isinstance(result, CommandResponse) or result.exit_code != 0:
                raise RuntimeError(f"failed: {line}")
            return result.stdout

        try:
            wait_until_ready(boat, sandbox_id)

            # 3. Once: write the certificate files that agent.env points at.
            run(agent.setup_command)

            # httpbin.org/bearer answers 401 with no key.
            # 200 means the gateway added the Test key.
            call = 'curl -s -o /dev/null -w "%{http_code}" https://httpbin.org/bearer'
            print(run(call))  # 200
        finally:
            stop_and_remove(boat, sandbox_id, delete=True)
```

## What goes where

> [tab] TypeScript
>
> | OneCLI | boat |
> | - | - |
> | `agent.env` | `env` in `boat.create` |
> | `agent.allowHosts` | `network: { mode: "allow", allow }` |
> | `agent.setupCommand` | `execCommand`, once, after `waitUntilReady` |
> | Stop | `stopAndRemove(boat, id, { delete: true })`, then `agent.disconnect()` |

> [tab] Python
>
> | OneCLI | boat |
> | - | - |
> | `agent.env` | `env` in `CreateSandboxRequest` |
> | `agent.allow_hosts` | `network=NetworkPolicyRequest(mode="allow", allow=...)` |
> | `agent.setup_command` | `exec_command`, once, after `wait_until_ready` |
> | Stop | `stop_and_remove(boat, sandbox_id, delete=True)`, then leaving the `with` block disconnects the agent |

The [Sandboxes overview](https://onecli.sh/docs/guides/sandboxes#how-it-works) explains each value.

## Good to know

* **`noEnv: true`** (`no_env=True` in Python) gives the sandbox none of the secrets stored in your boat account: no environment variables, secret files or credentials. The agent's settings come only from `env`.
* **The allow list.** A domain entry in boat's `allow` list opens port 443, matched by the host name the client sends, and port 80. OneCLI's hosts use 443.
* **Lifetime.** boat's `ttlSeconds` (`ttl_seconds` in Python) is how long the sandbox runs before boat stops it. Keep the agent's lifetime at least as long.
* **Long commands.** `execCommand` waits 30 seconds by default. Pass a longer `timeoutSeconds` (its fifth argument), or `timeout_seconds=` to `exec_command` in Python, for longer work.
* **Type checkers.** Pyright reports `ttl_seconds` and `no_env` as unknown parameters, because boat's Python models declare the API's names, `ttlSeconds` and `noEnv`. Both names work when the code runs.
* **Node clients.** Behind an allow list, Node's `http` and `https` modules and axios fail, because they send no host name to the gateway. Give them `agent.baseUrl(host)` instead, or `agent.base_url(host)` in Python. See the SDK reference for [TypeScript](https://onecli.sh/docs/sdks/node.md#a-client-that-cannot-use-a-proxy) or [Python](https://onecli.sh/docs/sdks/python.md#a-client-that-cannot-use-a-proxy).
* **boat's own key injection.** boat can also keep model keys out of a sandbox itself, with its AI credentials proxy. See [how OneCLI compares](https://onecli.sh/docs/guides/sandboxes#why-onecli-when-a-provider-injects-keys).

## From a terminal

To connect one boat sandbox that is already running, make a connect token as in [From a terminal](https://onecli.sh/docs/guides/sandboxes#from-a-terminal), then run its `install_command` in the sandbox, as it is, in place of `<install_command>`:

```bash theme={null}
boat exec <sandbox-id> -- sh -c '<install_command>'
```

## Versions

Written in December 2026 for `@onecli-sh/sdk` 4.1 and `@boatdev/sdk` 1.15 in TypeScript, and for `onecli-sdk` 0.1 and `boat-sdk` 1.15 in Python. The sandbox support of both OneCLI SDKs was run end to end in boat sandboxes, with the network allowed only to the agent's allowed hosts.

## Next steps

* [All sandbox providers](https://onecli.sh/docs/guides/sandboxes)
* [An agent for a sandbox, in the TypeScript SDK reference](https://onecli.sh/docs/sdks/node.md#an-agent-for-a-sandbox)
* [An agent for a sandbox, in the Python SDK reference](https://onecli.sh/docs/sdks/python.md#an-agent-for-a-sandbox)
* [Set what agents may do with each item](https://onecli.sh/docs/guides/agent-access.md)


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