SDK for ConTree container runtime with versioned filesystem state
Actively maintained. Last release 7 days ago, commits in 11 of the last 26 weeks. A safe choice.
pip install contree-sdkConTree SDK
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())