Skip to main content

ConTree SDK

PyPI version Python

Use one sandbox session to run commands, read and write files, search contents, and list directories. Save the filesystem as an image when you need to continue later or try a different approach.

This checkout contains the breaking 0.5 development API. Install it locally:

pip install -e .
# Include async transport and SQLite support when needed:
pip install -e ".[async]"

Use a sandbox session

The five tools are run, read_file, write_file, grep, and list_dir. Initialize the session from a token or from a saved profile. Use an image available on your endpoint.

Sync

"""Use the five sandbox tools in one session."""

from contree_sdk import create_sandbox_session


def main() -> None:
    with create_sandbox_session(image="tag:alpine:latest") as sandbox_session:
        # Write a file in the sandbox.
        sandbox_session.write_file("/work/message.txt", b"Hello from ConTree!\n")

        # Run a command and print its output.
        result = sandbox_session.run("cat", args=["/work/message.txt"])
        print(result.stdout)

        # Read the file as bytes.
        content = sandbox_session.read_file("/work/message.txt")
        print(content.decode())

        # Search file contents.
        matches = sandbox_session.grep("Hello", path="/work/message.txt")
        print(matches)

        # List the directory with file metadata.
        directory = sandbox_session.list_dir("/work")
        print(directory)


main()

Async

import asyncio

from contree_sdk import create_sandbox_session


async def main() -> None:
    async with create_sandbox_session(image="tag:alpine:latest") as sandbox_session:
        # Write a file in the sandbox.
        await sandbox_session.write_file("/work/message.txt", b"Hello from ConTree!\n")

        # Run a command and print its output.
        result = await sandbox_session.run("cat", args=["/work/message.txt"])
        print(result.stdout)

        # Read the file as bytes.
        content = await sandbox_session.read_file("/work/message.txt")
        print(content.decode())

        # Search file contents.
        matches = await sandbox_session.grep("Hello", path="/work/message.txt")
        print(matches)

        # List the directory with file metadata.
        directory = await sandbox_session.list_dir("/work")
        print(directory)


asyncio.run(main())

The command and file read both print Hello from ConTree!. The search prints /work/message.txt:1:Hello from ConTree!, and the listing shows metadata for message.txt.

The default LazySession (AsyncLazySession for async code) starts a VM on the first command and reuses it for later commands. After 10 idle seconds, it saves the filesystem and stops the VM automatically. The next command starts a new VM from those saved files. Processes and memory do not survive a snapshot. Normal context exit also saves pending changes.

To save after each command, select session_type=ContreeSession for Sync or session_type=ContreeAsyncSession for Async. Each command then uses a separate VM. See the complete save-after-every-command examples.

Follow a workflow

Task Guide
Configure credentials and use sync or async code Your first sandbox
Import a Docker image Import a Docker image
Build from a Dockerfile Build a Docker image
Select components and control their behavior Advanced usage
Upload inputs and download results Files
Continue after restarting Python Save and resume
Try alternatives from a checkpoint Branches
Control a running sandbox Operations
Connect deepagents Agent integration
Override policy or replace components Customization
Upgrade from the old SDK Migration

The documentation includes API references and failure-handling examples. The mini-swe-agent 2.4.6 bundled adapter needs a port before it can use this API; see the compatibility note.

Develop and test

uv sync --extra dev --extra docs
uv run pytest

The regular test run executes the Python scenarios in README and docs/ through markdown-pytest. The SDK and stores run normally; fixtures supply transport responses. No server credentials are required. See contributing for checks and how to add a scenario.

Licensed under Apache 2.0. Report vulnerabilities through the process in SECURITY.md.

Standalone programs with embedded tests are in examples/sync/ and examples/async/. See the examples guide for prerequisites and execution commands.

Metadata

Release files for contree-sdk 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for contree-sdk 0.5.0
File Size Uploaded Provenance Actions
contree_sdk-0.5.0.tar.gz 104.0 kB With provenance Details for contree_sdk-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for contree-sdk 0.5.0
File Interpreter ABI Platform Actions
contree_sdk-0.5.0-py3-none-any.whl Python 3 none any Details for contree_sdk-0.5.0-py3-none-any.whl

Total release size: 244.2 kB

Release files / contree_sdk-0.5.0.tar.gz

Download URL contree_sdk-0.5.0.tar.gz
Size 104.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f10b644cdc81f780d416726db8db6ce6015d95d772555480f90e5cf0cc3f1679
BLAKE2b-256 checksum
How to use checksums
b9ba9d2347c476173607a963ef75f04dcc59de115571d5bdaa043ff7aaa1b713
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / contree_sdk-0.5.0-py3-none-any.whl

Download URL contree_sdk-0.5.0-py3-none-any.whl
Size 140.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
540b18a291507ffb7359a731cdfe7669448e5cf6828d69931ab6bca18e97e416
BLAKE2b-256 checksum
How to use checksums
dc533cb82ccb0fd42bfd5cee33659d10c3a42c25876dc89e24af93ebb290de76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Security for contree-sdk 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for contree_sdk-0.5.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page