Metadata-Version: 2.4
Name: ceynox-sandbox
Version: 0.1.0a2
Summary: (alpha, invite-only) Python SDK for CeyNox Sandbox, hosted sandboxes for AI agents and any untrusted code, forked from the E2B Python SDK
Author-email: CeyNova Labs <support@ceynovahq.com>
Maintainer-email: CeyNova Labs <support@ceynovahq.com>
License-Expression: Apache-2.0
Project-URL: Homepage, https://ceynovahq.com
Keywords: sandbox,ai-agents,code-execution,ceynox
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: LICENSE.upstream-package
License-File: LICENSE.upstream-repository
License-File: NOTICE
Requires-Dist: python-dateutil>=2.8.2
Requires-Dist: httpx<1.0.0,>=0.27.0
Requires-Dist: attrs>=23.2.0
Requires-Dist: protobuf-py<0.7,>=0.6.0
Requires-Dist: h2<5,>=4.4.1
Requires-Dist: packaging>=24.1
Requires-Dist: connectrpc<0.13,>=0.12.1
Requires-Dist: pyqwest<0.15,>=0.12.0
Dynamic: license-file

# CeyNox Sandbox SDK for Python

> ⚠️ **Alpha: not for production use.** CeyNox Sandbox is not open to the public yet. This pre-release is for invited testers only; you need an invitation to get an API address and key, which your console then shows you. Interfaces may change between alpha releases without notice. Interested? Email [support@ceynovahq.com](mailto:support@ceynovahq.com).

**Run untrusted code, from AI agents or anywhere else, in isolated cloud sandboxes instead of on your own machine.**

[![PyPI](https://img.shields.io/pypi/v/ceynox-sandbox?include_prereleases&label=pypi)](https://pypi.org/project/ceynox-sandbox/)
[![Python versions](https://img.shields.io/pypi/pyversions/ceynox-sandbox)](https://pypi.org/project/ceynox-sandbox/)
[![Licence](https://img.shields.io/pypi/l/ceynox-sandbox)](https://pypi.org/project/ceynox-sandbox/)

## Features

- Isolated Linux sandboxes, each separate from your machine and from every other customer's sandbox.
- Commands in the foreground or background, with streamed output, exit codes and timeouts.
- Files: read, write and list.
- Pause a sandbox with its memory and disk, and resume it later.
- Sync (`Sandbox`) and async (`AsyncSandbox`) APIs, fully typed.
- The `ceynox-sandbox` command: sandboxes, commands, file copies and SSH from a terminal.
- Compatible with code written for the E2B SDK.

## Requirements

- Python 3.11 or later.
- An invitation to the alpha: your console then gives you your API address and an API key.

## Install

```sh
pip install --pre ceynox-sandbox
```

`--pre` is needed while only pre-releases exist.

## Quick start

Save your API key and your API's address once. Your console's API keys page shows this line with your address filled in; the command asks for the key:

```sh
ceynox-sandbox login --api-url https://api.<your environment>
```

Then:

```python
from ceynox_sandbox import Sandbox

with Sandbox.create() as sandbox:
    result = sandbox.commands.run("python3 -c 'print(6 * 7)'")
    print(result.exit_code, result.stdout)  # 0 42
```

The sandbox is killed when the `with` block ends.

## Usage

### Commands

```python
from ceynox_sandbox import CommandExitException, Sandbox

with Sandbox.create() as sandbox:
    result = sandbox.commands.run("echo $NAME", cwd="/tmp", envs={"NAME": "hello"})
    print(result.stdout)  # hello

    # A non-zero exit raises, carrying the exit code and the output.
    try:
        sandbox.commands.run("exit 3")
    except CommandExitException as error:
        print(error.exit_code)  # 3

    # Stream output as it arrives, and end the command after 10 seconds.
    sandbox.commands.run(
        "for i in 1 2 3; do echo $i; sleep 1; done",
        on_stdout=lambda data: print("out:", data, end=""),
        timeout=10,
    )

    # Run as root instead of the unprivileged `user`.
    print(sandbox.commands.run("whoami", user="root").stdout)  # root

    # In the background: wait for it later.
    handle = sandbox.commands.run("sleep 2 && echo done", background=True)
    print(handle.wait().stdout)  # done
```

### Files

```python
with Sandbox.create() as sandbox:
    sandbox.files.write("/home/user/hello.txt", "hello")
    print(sandbox.files.read("/home/user/hello.txt"))  # hello
    for entry in sandbox.files.list("/home/user"):
        print(entry.name, entry.type)
```

### Async

```python
import asyncio

from ceynox_sandbox import AsyncSandbox


async def main() -> None:
    async with await AsyncSandbox.create() as sandbox:
        result = await sandbox.commands.run("uname -a")
        print(result.stdout)


asyncio.run(main())
```

### Lifetime, pause and resume

```python
sandbox = Sandbox.create(timeout=600)  # ends after 10 minutes unless extended
sandbox.set_timeout(3600)              # now an hour from now

sandbox.pause()                        # keeps its memory and disk
same = Sandbox.connect(sandbox.sandbox_id)  # resumes it where it left off
same.kill()
```

### Passing the key and address in code

```python
import os

sandbox = Sandbox.create(api_key=os.environ["MY_CEYNOX_KEY"], api_url="https://api.<your environment>")
```

## Command line

The package installs `ceynox-sandbox`:

```sh
ceynox-sandbox login --api-url https://api.<your environment>   # save your key and address
ceynox-sandbox create                 # prints the new sandbox's id
ceynox-sandbox list
ceynox-sandbox exec <id> -- uname -a
ceynox-sandbox cp ./app <id>:app
ceynox-sandbox ssh <id>
ceynox-sandbox profiles               # the saved profiles and their addresses
ceynox-sandbox --help
ceynox-sandbox --version
```

It lists, creates, pauses, resumes and kills sandboxes, runs commands, copies files, forwards ports and opens SSH sessions with short-lived certificates.

## Configuration

| Setting | In code | Environment | What it sets |
|---|---|---|---|
| API key | `api_key` | `CEYNOX_API_KEY` | Your API key (keys start with `cnx_`) |
| API address | `api_url` | `CEYNOX_API_URL` | Your API's address (`https://…`) |
| Profile | `profile` | `CEYNOX_PROFILE` | A profile saved with `ceynox-sandbox login --profile <name>`, used as a whole |

The key and the address always go together:

- **Neither given** in code or the environment: both come from the saved `default` profile.
- **Only one given:** the other is never taken from the default profile. Without a key nothing is sent; without an address the production API is used.
- **A profile named** (`profile=` or `CEYNOX_PROFILE`): that profile is used as a whole, filling whichever of the two is not given.

`ceynox-sandbox login --profile <name> --api-url …` saves more than one profile, for example one per environment.

## Error handling

Every error the SDK raises is a `CeyNoxException`:

```python
from ceynox_sandbox import (
    ApiUnreachableException,
    AuthenticationException,
    CeyNoxException,
    Sandbox,
)

try:
    sandbox = Sandbox.create()
except AuthenticationException as error:
    print("no key, or the key was refused:", error)
except ApiUnreachableException as error:
    print("the API could not be reached at", error.api_url)
except CeyNoxException as error:
    print("something else went wrong:", error)
```

As in the E2B SDK, `AuthenticationException` and `ServiceBusyException` are not `SandboxException`s, so catch `CeyNoxException` to handle everything.

## Security

- Your key and a sandbox's access tokens are sent only over HTTPS. Plain HTTP is refused except to this computer (`localhost`, `127.0.0.0/8`, `::1`).
- A key is sent only to the address it is paired with (see Configuration), and a key that is not a CeyNox key (`cnx_…`) is never sent, so another provider's key left in the environment stays where it is.
- Saved profiles live in `~/.ceynox/credentials.json`, written readable only by you, and refused if anyone else can read it. `login` reads the key from the terminal or standard input, never from the command line.
- Output from a sandbox is produced by code you may not control: treat it as untrusted data.
- To report a vulnerability, email [support@ceynovahq.com](mailto:support@ceynovahq.com).

## Coming from E2B

This SDK is a fork of the E2B Python SDK and keeps its interface, so code written for E2B needs little change: import from `ceynox_sandbox` and use a CeyNox key. Anything the service does not offer yet fails at once with a "not supported by CeyNox Sandbox yet" error, before any request is made. A few E2B options are kept only for compatibility and will go before 1.0: `keep_memory` (a pause always keeps memory) and the `headers` option (use `api_headers`).

## Versioning

Pre-1.0 alpha; no stability guarantees; not for production. Breaking changes are possible between alphas. From 1.0 the package follows semantic versioning. `ceynox_sandbox.__version__` and `ceynox-sandbox --version` say which version is installed.

## Support

Email [support@ceynovahq.com](mailto:support@ceynovahq.com).

## Licence

Apache License 2.0 (`LICENSE`) for CeyNova Labs' code. The parts taken from the E2B SDK keep their original licences, included as `LICENSE.upstream-package` (MIT) and `LICENSE.upstream-repository` (Apache 2.0). `NOTICE` says where the code came from and what was changed.
