Skip to main content

Python SDK for Sleigh runtime server.

Project description

Sleigh Python SDK

Python SDK for the Sleigh runtime server.

Two client variants are included:

  • LangChain Tool variant: one-call as_langchain_tool() (returns StructuredTool)
  • MCP variant: expose runtime APIs as MCP tools over stdio

1. Install

pip install .

Optional extras:

pip install ".[langchain]"
pip install ".[mcp]"

2. Base Python Client

from sdk import SleighClient

client = SleighClient(base_url="http://127.0.0.1:8080")
session_token = "sess_demo"
created = client.create_sandbox(session_token=session_token, image="alpine:3.20")
sandbox_id = created["id"]

3. Ordered Workflow (AI Coding)

Run multiple steps in one request and stop early on failure/timeout:

result = client.run_workflow(
    session_token=session_token,
    steps=[
        {"action": "create_sandbox", "image": "alpine:3.20", "memory_limit_mb": 512},
        {"action": "exec_command", "command": "echo hello", "wait": True, "wait_timeout_seconds": 10},
        {"action": "create_snapshot"},
        {"action": "exec_command", "command": "uname -a", "wait": True},
    ],
)
print(result["stopped_early"], result["steps"])

4. Sandbox Read API (AI Coding)

read_result = client.read_sandbox(
    session_token=session_token,
    sandbox_id=sandbox_id,
    command="rg",
    args=["TODO", "/workspace"],
    timeout_seconds=10,
    max_output_bytes=65536,
    max_lines=200,
)
print(read_result)

5. Patch API (Sandbox Semantic)

patch_workspace targets:

  • POST /sandboxes/{id}/ops/patch
  • validates sandbox auth + mounted workspace path ownership
  • workspace_path is required and is resolved under SERVER_MOUNT_ALLOWED_ROOT
result = client.patch_workspace(
    session_token=session_token,
    sandbox_id=sandbox_id,
    workspace_path="/test",
    patch="*** Begin Patch\n*** End Patch\n",
)

6. Low-Memory Create Guard

When host available memory ratio:

  • < 5%: create is blocked
  • >= 5% and < 8%: create requires confirm_low_memory=True
created = client.create_sandbox(
    session_token=session_token,
    image="alpine:3.20",
    confirm_low_memory=True,
)

7. More Examples

  • LangChain integration: ../README_langchain.md
  • MCP integration: ../README_mcp.md

8. Session Exec History

list_session_exec_tasks accepts optional session_id. If omitted, SDK uses session_token as session_id automatically:

history = client.list_session_exec_tasks(
    session_token=session_token,
    limit=20,
)
print(history)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sleigh_sdk-0.1.3.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sleigh_sdk-0.1.3-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file sleigh_sdk-0.1.3.tar.gz.

File metadata

  • Download URL: sleigh_sdk-0.1.3.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sleigh_sdk-0.1.3.tar.gz
Algorithm Hash digest
SHA256 8d2e1db4f02e9144a6305091c9105fcb3d20dd6fd5b7ae16d8a71052004cecaf
MD5 a7b788cfc70bb7fe38bf6340fc61d093
BLAKE2b-256 503638b881f53ce5ac01d9955ec135f7ab5d3e4d435ff2531f7e029affcbaf96

See more details on using hashes here.

File details

Details for the file sleigh_sdk-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: sleigh_sdk-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sleigh_sdk-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6b305f34625088f1f4cc92156aff58a92d902952480d26a0c47efa8dafa188aa
MD5 b1f11886c08ee8ef27215ffdb1f5d070
BLAKE2b-256 9f632c89a54504cfa00bc8cc26da6dff5229d28a9b3ab4f7350d642c21bbbffe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page