> ## 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 Daytona sandbox

> Start a Daytona sandbox from TypeScript or Python with its own OneCLI agent: the agent's settings, a domain allow list for OneCLI, and no key inside it.

Your code starts a Daytona 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.

> [!WARNING]
>
> On Daytona's Tier 1 and Tier 2, the organization's network limits apply to every sandbox and a sandbox cannot change them: only Daytona's [essential services](https://www.daytona.io/docs/en/network-limits#essential-services) stay reachable, and `onecli.sh` is not one of them (December 2026). Use Tier 3 or Tier 4.

## 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 Daytona API key in `DAYTONA_API_KEY`, from your Daytona dashboard.
* 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 @daytona/sdk
```

```bash Python theme={null}
pip install onecli-sdk "daytona[v0-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 { Daytona } from "@daytona/sdk";

const onecli = new OneCLI(); // reads ONECLI_API_KEY
const daytona = new Daytona(); // reads DAYTONA_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: "daytona",
  ttlSeconds: 3600,
});

// 2. The sandbox: the agent's settings, and a network to OneCLI only.
const sandbox = await daytona.v0.create({
  envVars: agent.env,
  domainAllowList: agent.allowHosts.join(","),
});

try {
  // 3. Once: write the certificate files that agent.env points at.
  const setup = await sandbox.process.executeCommand(agent.setupCommand);
  if (setup.exitCode !== 0) throw new Error(`setup failed: ${setup.result}`);

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

```python Python theme={null}
from daytona import Daytona
from daytona.v0 import CreateSandboxFromSnapshotParams
from onecli import OneCLI

# OneCLI reads ONECLI_API_KEY, and Daytona reads DAYTONA_API_KEY.
with OneCLI() as onecli, Daytona() as daytona:
    # 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="daytona",
        ttl_seconds=3600,
    ) as agent:
        # 2. The sandbox: the agent's settings, and a network to OneCLI only.
        sandbox = daytona.v0.create(
            CreateSandboxFromSnapshotParams(
                env_vars=agent.env,
                domain_allow_list=",".join(agent.allow_hosts),
            )
        )

        try:
            # 3. Once: write the certificate files that agent.env points at.
            setup = sandbox.process.exec(agent.setup_command)
            if setup.exit_code != 0:
                raise RuntimeError(f"setup failed: {setup.result}")

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

## What goes where

> [tab] TypeScript
>
> | OneCLI | Daytona |
> | - | - |
> | `agent.env` | `envVars` in `daytona.v0.create` |
> | `agent.allowHosts` | `domainAllowList`, one string with the hosts separated by commas |
> | `agent.setupCommand` | `sandbox.process.executeCommand`, once. Check `exitCode`: it does not throw. |
> | Stop | `sandbox.delete()`, then `agent.disconnect()` |

> [tab] Python
>
> | OneCLI | Daytona |
> | - | - |
> | `agent.env` | `env_vars` in `CreateSandboxFromSnapshotParams`, for `daytona.v0.create` |
> | `agent.allow_hosts` | `domain_allow_list`, one string with the hosts separated by commas |
> | `agent.setup_command` | `sandbox.process.exec`, once. Check `exit_code`: it does not raise an error. |
> | Stop | `sandbox.delete()`, 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

* **The `v0` client.** In `@daytona/sdk` 2, sandboxes are made with `daytona.v0.create`, as in Daytona's own docs. The Python `daytona` package 2 has the same `v0` client, which needs the `v0-sdk` extra: the install line adds it.
* **An allow list is strict.** With a domain allow list set, the sandbox reaches only those hosts. Add package registries such as `registry.npmjs.org` or `pypi.org` if the agent installs packages.
* **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).
* **Daytona's own key injection.** Daytona can also add a key to a sandbox's calls itself, with secrets that the sandbox sees only as placeholders. See [how OneCLI compares](https://onecli.sh/docs/guides/sandboxes#why-onecli-when-a-provider-injects-keys).

## From a terminal

To connect one Daytona 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}
daytona sandbox exec <sandbox-id> -- sh -c '<install_command>'
```

## Versions

Written in December 2026 for `@onecli-sh/sdk` 4.1 and `@daytona/sdk` 2.7 in TypeScript, and for `onecli-sdk` 0.1 and `daytona` 2.8 in Python.

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