Metadata-Version: 2.3
Name: contree-cli
Version: 0.7.1
Summary: CLI client for the ConTree sandbox platform
Keywords: sandbox,cli,vm,ai-agent,contree
Author: Dmitry Orlov
Author-email: Dmitry Orlov <mosquito@nebius.com>
License: 
                                          Apache License
                                    Version 2.0, January 2004
                                 http://www.apache.org/licenses/
         
            TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
         
            1. Definitions.
         
               "License" shall mean the terms and conditions for use, reproduction,
               and distribution as defined by Sections 1 through 9 of this document.
         
               "Licensor" shall mean the copyright owner or entity authorized by
               the copyright owner that is granting the License.
         
               "Legal Entity" shall mean the union of the acting entity and all
               other entities that control, are controlled by, or are under common
               control with that entity. For the purposes of this definition,
               "control" means (i) the power, direct or indirect, to cause the
               direction or management of such entity, whether by contract or
               otherwise, or (ii) ownership of fifty percent (50%) or more of the
               outstanding shares, or (iii) beneficial ownership of such entity.
         
               "You" (or "Your") shall mean an individual or Legal Entity
               exercising permissions granted by this License.
         
               "Source" form shall mean the preferred form for making modifications,
               including but not limited to software source code, documentation
               source, and configuration files.
         
               "Object" form shall mean any form resulting from mechanical
               transformation or translation of a Source form, including but
               not limited to compiled object code, generated documentation,
               and conversions to other media types.
         
               "Work" shall mean the work of authorship, whether in Source or
               Object form, made available under the License, as indicated by a
               copyright notice that is included in or attached to the work
               (an example is provided in the Appendix below).
         
               "Derivative Works" shall mean any work, whether in Source or Object
               form, that is based on (or derived from) the Work and for which the
               editorial revisions, annotations, elaborations, or other modifications
               represent, as a whole, an original work of authorship. For the purposes
               of this License, Derivative Works shall not include works that remain
               separable from, or merely link (or bind by name) to the interfaces of,
               the Work and Derivative Works thereof.
         
               "Contribution" shall mean any work of authorship, including
               the original version of the Work and any modifications or additions
               to that Work or Derivative Works thereof, that is intentionally
               submitted to the Licensor for inclusion in the Work by the copyright owner
               or by an individual or Legal Entity authorized to submit on behalf of
               the copyright owner. For the purposes of this definition, "submitted"
               means any form of electronic, verbal, or written communication sent
               to the Licensor or its representatives, including but not limited to
               communication on electronic mailing lists, source code control systems,
               and issue tracking systems that are managed by, or on behalf of, the
               Licensor for the purpose of discussing and improving the Work, but
               excluding communication that is conspicuously marked or otherwise
               designated in writing by the copyright owner as "Not a Contribution."
         
               "Contributor" shall mean Licensor and any individual or Legal Entity
               on behalf of whom a Contribution has been received by the Licensor and
               subsequently incorporated within the Work.
         
            2. Grant of Copyright License. Subject to the terms and conditions of
               this License, each Contributor hereby grants to You a perpetual,
               worldwide, non-exclusive, no-charge, royalty-free, irrevocable
               copyright license to reproduce, prepare Derivative Works of,
               publicly display, publicly perform, sublicense, and distribute the
               Work and such Derivative Works in Source or Object form.
         
            3. Grant of Patent License. Subject to the terms and conditions of
               this License, each Contributor hereby grants to You a perpetual,
               worldwide, non-exclusive, no-charge, royalty-free, irrevocable
               (except as stated in this section) patent license to make, have made,
               use, offer to sell, sell, import, and otherwise transfer the Work,
               where such license applies only to those patent claims licensable
               by such Contributor that are necessarily infringed by their
               Contribution(s) alone or by combination of their Contribution(s)
               with the Work to which such Contribution(s) was submitted. If You
               institute patent litigation against any entity (including a
               cross-claim or counterclaim in a lawsuit) alleging that the Work
               or a Contribution incorporated within the Work constitutes direct
               or contributory patent infringement, then any patent licenses
               granted to You under this License for that Work shall terminate
               as of the date such litigation is filed.
         
            4. Redistribution. You may reproduce and distribute copies of the
               Work or Derivative Works thereof in any medium, with or without
               modifications, and in Source or Object form, provided that You
               meet the following conditions:
         
               (a) You must give any other recipients of the Work or
                   Derivative Works a copy of this License; and
         
               (b) You must cause any modified files to carry prominent notices
                   stating that You changed the files; and
         
               (c) You must retain, in the Source form of any Derivative Works
                   that You distribute, all copyright, patent, trademark, and
                   attribution notices from the Source form of the Work,
                   excluding those notices that do not pertain to any part of
                   the Derivative Works; and
         
               (d) If the Work includes a "NOTICE" text file as part of its
                   distribution, then any Derivative Works that You distribute must
                   include a readable copy of the attribution notices contained
                   within such NOTICE file, excluding any notices that do not
                   pertain to any part of the Derivative Works, in at least one
                   of the following places: within a NOTICE text file distributed
                   as part of the Derivative Works; within the Source form or
                   documentation, if provided along with the Derivative Works; or,
                   within a display generated by the Derivative Works, if and
                   wherever such third-party notices normally appear. The contents
                   of the NOTICE file are for informational purposes only and
                   do not modify the License. You may add Your own attribution
                   notices within Derivative Works that You distribute, alongside
                   or as an addendum to the NOTICE text from the Work, provided
                   that such additional attribution notices cannot be construed
                   as modifying the License.
         
               You may add Your own copyright statement to Your modifications and
               may provide additional or different license terms and conditions
               for use, reproduction, or distribution of Your modifications, or
               for any such Derivative Works as a whole, provided Your use,
               reproduction, and distribution of the Work otherwise complies with
               the conditions stated in this License.
         
            5. Submission of Contributions. Unless You explicitly state otherwise,
               any Contribution intentionally submitted for inclusion in the Work
               by You to the Licensor shall be under the terms and conditions of
               this License, without any additional terms or conditions.
               Notwithstanding the above, nothing herein shall supersede or modify
               the terms of any separate license agreement you may have executed
               with Licensor regarding such Contributions.
         
            6. Trademarks. This License does not grant permission to use the trade
               names, trademarks, service marks, or product names of the Licensor,
               except as required for reasonable and customary use in describing the
               origin of the Work and reproducing the content of the NOTICE file.
         
            7. Disclaimer of Warranty. Unless required by applicable law or
               agreed to in writing, Licensor provides the Work (and each
               Contributor provides its Contributions) on an "AS IS" BASIS,
               WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
               implied, including, without limitation, any warranties or conditions
               of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
               PARTICULAR PURPOSE. You are solely responsible for determining the
               appropriateness of using or redistributing the Work and assume any
               risks associated with Your exercise of permissions under this License.
         
            8. Limitation of Liability. In no event and under no legal theory,
               whether in tort (including negligence), contract, or otherwise,
               unless required by applicable law (such as deliberate and grossly
               negligent acts) or agreed to in writing, shall any Contributor be
               liable to You for damages, including any direct, indirect, special,
               incidental, or consequential damages of any character arising as a
               result of this License or out of the use or inability to use the
               Work (including but not limited to damages for loss of goodwill,
               work stoppage, computer failure or malfunction, or any and all
               other commercial damages or losses), even if such Contributor
               has been advised of the possibility of such damages.
         
            9. Accepting Warranty or Additional Liability. While redistributing
               the Work or Derivative Works thereof, You may choose to offer,
               and charge a fee for, acceptance of support, warranty, indemnity,
               or other liability obligations and/or rights consistent with this
               License. However, in accepting such obligations, You may act only
               on Your own behalf and on Your sole responsibility, not on behalf
               of any other Contributor, and only if You agree to indemnify,
               defend, and hold each Contributor harmless for any liability
               incurred by, or claims asserted against, such Contributor by reason
               of your accepting any such warranty or additional liability.
         
            END OF TERMS AND CONDITIONS
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
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: Topic :: Software Development :: Build Tools
Classifier: Topic :: System :: Shells
Classifier: Typing :: Typed
Requires-Python: >=3.10
Project-URL: Homepage, https://contree.dev
Project-URL: Documentation, https://docs.contree.dev/cli/
Project-URL: Repository, https://github.com/nebius/contree-cli
Project-URL: Issues, https://github.com/nebius/contree-cli/issues
Project-URL: Changelog, https://github.com/nebius/contree-cli/releases
Description-Content-Type: text/markdown

# contree-cli

[![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)
[![Zero Dependencies](https://img.shields.io/badge/dependencies-0-brightgreen.svg)](#zero-dependencies)
[![PyPI](https://img.shields.io/pypi/v/contree-cli.svg)](https://pypi.org/project/contree-cli/)

Command-line client for the [ConTree](https://contree.dev) sandboxing platform — secure, VM-isolated sandboxes with git-like branching for AI agents and developers.

```bash
eval $(contree use tag:ubuntu:latest)   # pick a base image for current session
contree run apt-get update -qq          # each run snapshots the result
contree run apt-get install -y curl     # builds on the previous snapshot
contree session branch experiment       # branch the sandbox state
contree run -- make test                # experiment freely
contree session checkout main           # switch back instantly
contree session rollback -- -2          # or rewind two steps
```

## What is ConTree?

[ConTree](https://contree.dev) is a secure sandbox API that runs every command inside a VM-isolated instance and snapshots the full filesystem after each execution. These snapshots (called **images**) form a tree — branch from any checkpoint, explore paths in parallel, and roll back on failure.

**Built for AI agents that think ahead:**

- **Tree-search execution** — branch sandbox state so an agent can explore multiple solution paths in parallel and keep the best one
- **Instant rollback** — backtrack to any previous checkpoint without rebuilding from scratch
- **Safe code execution** — run untrusted or LLM-generated code inside VM-level isolation; crashes and side effects stay in the sandbox
- **Session continuity** — rewind and resume long-running agent workflows with full filesystem context preserved

`contree-cli` talks to the ConTree API. Install it, authenticate with your project token, and create sandboxes, run commands, inspect filesystems, and manage sessions — all from your terminal, shell scripts, or agent toolchains.

## Install

```bash
pip install contree-cli
```

Or with [uv](https://docs.astral.sh/uv/):

```bash
uv tool install contree-cli
```

<details>
<summary>More options (pipx, from source)</summary>

```bash
# pipx
pipx install contree-cli

# From source
git clone https://github.com/nebius/contree-cli.git
cd contree-cli
pip install .
```

</details>

Verify:

```bash
contree --help
```

**Requirements:** Python 3.10+ and nothing else. Zero external dependencies — stdlib only.

## Quick Start

### 1. Authenticate

```bash
contree auth
```

You'll be prompted to enter your API token and project ID. The CLI verifies the token and saves credentials to `~/.config/contree/auth.ini` (override the data directory via `CONTREE_HOME`).

If `--token`/`--url`/`--project` flags are omitted, `contree auth` reads `CONTREE_TOKEN` (or `NEBIUS_API_KEY`), `CONTREE_URL`, and `CONTREE_PROJECT` (or `NEBIUS_AI_PROJECT`) from the environment instead of prompting. These variables are read only during registration; runtime commands use the saved profile only.

### 2. Install agent skills (optional)

```bash
contree skill install
```

Autodetects installed agents (Claude Code, Codex, OpenCode, Cline, Amp) and installs ConTree skill files into their skill directories. Use `contree skill install -F` to force-overwrite.

### 3. Start a session

```bash
eval $(contree use tag:ubuntu:latest)
```

This picks a base image and creates a session. The `eval` wrapper exports the session variable so subsequent commands share the same state.

### 4. Run commands

```bash
contree run uname -a                  # direct execution
contree run apt-get install -y curl   # installs persist to next run
contree run -s -- 'echo $PATH'        # shell mode for expansions
```

Each non-disposable `run` produces a new image — a full filesystem checkpoint.

### 5. Inspect without spawning

```bash
contree ls /usr/bin          # list files (no VM needed)
contree cat /etc/os-release  # read files (no VM needed)
contree cp /app/output.log . # download to local machine
```

### 6. Branch and roll back

```bash
contree session branch experiment     # create a branch
contree run -- make test              # experiment on it
contree session checkout main         # switch back
contree session rollback              # undo last run (default: back 1 entry)
```

## Interactive Shell

`contree shell` starts a REPL where bare commands run in the sandbox automatically:

```
$ contree shell
contree:/> apt-get update -qq
...
contree:/> apt-get install -y curl
...
contree:/> curl -sI https://example.com
HTTP/2 200
...
contree:/> cd /etc
contree:/etc> cat os-release
PRETTY_NAME="Ubuntu 24.04 LTS"
...
contree:/etc> contree session branch experiment
Created branch 'experiment'
contree:/etc> exit
```

The shell provides tab completion for commands, paths, image tags, and operation IDs. `ls` and `cat` map to the fast API inspection commands by default. `vim`/`vi`/`nano` open `contree file edit` with your local `$EDITOR`.

## Commands

| Command | Aliases | Description |
|---|---|---|
| `use IMAGE` | `ci` | Set or show current session image |
| `run [-- CMD]` | `r` | Spawn a sandbox instance, execute command |
| `images [--prefix]` | `i`, `img` | List and import images |
| `tag UUID TAG` | `t` | Tag or untag an image |
| `ps` | | List operations (shortcut for `operation ls`) |
| `kill UUID [UUID...]` | | Cancel operations (shortcut for `operation cancel`; `--all` for all active) |
| `show UUID` | | Show operation result |
| `operation list` | `op`, `ls` | Same as `ps` (canonical) |
| `operation show UUID...` | `sh` | Multi-UUID inspect |
| `operation wait UUID...` | `w` | Block until each op finishes (or `--all`; `--timeout`) |
| `operation cancel UUID...` | `kill`, `k` | Multi-UUID cancel (or `--all`) |
| `ls [PATH]` | | List files in session image (no VM) |
| `cat PATH` | | Show file content from session image (no VM) |
| `cp PATH DEST` | | Download file from image to local path |
| `file edit PATH` | `e` | Edit remote file via local `$EDITOR` |
| `file cp SRC DEST` | `f` | Upload local file into session image |
| `cd [PATH]` | | Change working directory in session |
| `env [KEY=VALUE ...]` | | Manage session environment variables |
| `session` | `s` | Show current session info |
| `session list` | `ls` | List all sessions |
| `session branch` | `br` | Create or list branches |
| `session checkout` | `co` | Switch active branch |
| `session rollback [N]` | `rb` | Revert N steps in history |
| `session show` | | Display session history DAG |
| `auth` | | Configure authentication (secure prompt) |
| `auth list` | `ls` | List saved profiles |
| `auth switch NAME` | | Switch active profile |
| `auth remove NAME` | `rm` | Remove a saved profile |
| `skill install [SPEC ...]` | | Install agent skills |
| `skill remove SPEC [...]` | | Remove installed skills |
| `skill upgrade [SPEC ...]` | | Upgrade skills (no args = all) |
| `skill list` | `ls` | List installed skills |
| `shell` | `sh` | Start interactive REPL |
| `agent` | `man` | Show manual |

See the full [command reference](https://docs.contree.dev/cli/commands/) for all flags and options.

## Execution Modes

The `run` command supports four execution modes:

```bash
# Direct — arguments are the command
contree run uname -a

# Shell — arguments joined, passed to sh -c
contree run -s -- 'echo $HOME && ls /'

# Interpreter — local script executed remotely
contree run -I ./deploy.sh

# Piped stdin — stdin forwarded to the command
echo 'SELECT 1' | contree run -- psql
```

### File injection

Mount local files into the sandbox:

```bash
contree run --file ./app.py:/app/app.py -- python /app/app.py
contree run --file ./config.yaml --file ./data.csv -- ./process.sh
```

File specs support permissions: `host_path[:remote_path][:uUID][:gGID][:mMODE]`

### Shebang scripts

```bash
#!/usr/bin/env -S contree run -I
apt-get update -qq
apt-get install -y curl
curl https://example.com
```

Save as `setup.sh`, `chmod +x`, and run it directly.

## Sessions and Branching

Sessions track your sandbox state with git-like branching and history:

```
main:  A ── B ── C ── D
                  \
experiment:        E ── F
```

Every `run` creates a checkpoint. Branch to explore alternatives. Roll back to any point. Switch branches instantly.

```bash
contree session                       # show current state
contree session show                  # display history DAG
contree session branch feature        # create branch from HEAD
contree session checkout feature      # switch to it
contree session rollback -- -3        # go back 3 steps (note `--`; bare `3` is absolute id)
contree session use other-session     # import image from another session
```

## Output Formats

All commands support structured output via `-f`/`--format`:

```bash
contree images -f json                # JSON (one object per line)
contree images -f json-pretty         # pretty-printed JSON array
contree ps -f csv                     # RFC 4180 CSV
contree ps -f tsv                     # tab-separated values
contree ls -f table                   # ASCII table
```

Pipe JSON output into `jq`, feed CSV into spreadsheets, or parse programmatically in your agent toolchain.

## Configuration

### Config file

`$XDG_CONFIG_HOME/contree/auth.ini` (default: `~/.config/contree/auth.ini`; override via `$CONTREE_HOME`):

```ini
[DEFAULT]
profile = default

[profile:default]
token = eyJ...
url = https://api.studio.nebius.com/sandboxes
type = iam
project = your-project-id
```

### Multiple profiles

```bash
contree auth --profile=staging        # save staging token
contree auth --profile=prod           # save production token
contree auth profiles                 # list all profiles + status probe
contree auth profiles --offline       # list profiles without network checks
contree -f json auth profiles         # structured profile health output
contree auth switch staging           # switch active profile
```

### Environment variables

Read at runtime (any command):

| Variable | Purpose |
|---|---|
| `CONTREE_HOME` | Data directory (default `$XDG_CONFIG_HOME/contree`, or `~/.config/contree`) |
| `CONTREE_PROFILE` | Active profile name (selects which profile commands use) |
| `CONTREE_SESSION` | Explicit session key (for multi-terminal workflows) |
| `CONTREE_SESSION_DB` | Path to session SQLite database |

Read only by `contree auth` (registration-time fallbacks for omitted flags):

| Variable | Used for |
|---|---|
| `CONTREE_TOKEN` / `NEBIUS_API_KEY` | `--token` |
| `CONTREE_URL` | `--url` |
| `CONTREE_PROJECT` / `NEBIUS_AI_PROJECT` | `--project` |

Credentials come strictly from the saved profile at runtime. `--token`, `--url`, `--project` CLI flags override profile fields for a single invocation.

## Zero Dependencies

`contree-cli` uses only the Python standard library. No `requests`, no `click`, no `rich` — just `http.client`, `argparse`, `json`, `sqlite3`, and friends. It runs anywhere Python 3.10+ is available with nothing to install beyond the package itself.

## Development

```bash
git clone https://github.com/nebius/contree-cli.git
cd contree-cli
uv sync --group dev
```

```bash
make lint       # ruff check --fix
make types      # mypy strict mode
make check      # lint + types
make tests      # lint + types + pytest
```

The project enforces strict mypy, ruff linting (E/F/W/I/UP/B/SIM/RUF rules), and full test coverage across 23+ test modules.

## Documentation

Full documentation is available at **[docs.contree.dev/cli](https://docs.contree.dev/cli/)**, including:

- [Tutorial](https://docs.contree.dev/cli/tutorial/) — step-by-step from installation to automation
- [Command Reference](https://docs.contree.dev/cli/commands/) — every command, flag, and subcommand

## Links

- [ConTree Platform](https://contree.dev)
- [Documentation](https://docs.contree.dev/cli/)
- [PyPI](https://pypi.org/project/contree-cli/)
- [Issues](https://github.com/nebius/contree-cli/issues)
- [Releases](https://github.com/nebius/contree-cli/releases)

## Copyright

Nebius B.V. 2026, Licensed under the Apache License, Version 2.0 (see "LICENSE" file).
