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 = client.create_session_token()["session_token"]
created = client.create_sandbox(session_token=session_token, image="alpine:3.20")
sandbox_id = created["sandbox_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 and targets directory inside sandbox filesystem
  • sandbox_path is required and must be an absolute directory path in sandbox
  • service exports sandbox dir to host temp workspace, applies patch, and syncs back
  • quality checks: run pre-commit when config exists; otherwise auto-detect language for fallback checks
  • patch must be unified diff text (not raw file content), e.g. with *** Begin Patch or diff --git headers
  • for create/delete/rename patches, include complete git metadata headers (e.g. new file mode, deleted file mode, rename from, rename to, index)
  • write_mode=replace_file is supported for full overwrite by raw source content
result = client.patch_workspace(
    session_token=session_token,
    sandbox_id=sandbox_id,
    sandbox_path="/app",
    patch="*** Begin Patch\n*** End Patch\n",
)

# Full overwrite mode (raw source content)
rewrite_result = client.patch_workspace(
    session_token=session_token,
    sandbox_id=sandbox_id,
    sandbox_path="/app",
    write_mode="replace_file",
    target_file_path="calculator.py",
    content="print('hello from overwrite mode')\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,
    request_timeout_seconds=180,
)

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.8.tar.gz (9.0 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.8-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sleigh_sdk-0.1.8.tar.gz
  • Upload date:
  • Size: 9.0 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.8.tar.gz
Algorithm Hash digest
SHA256 7bcb491536fcbafce31d55bd87ab431070c9a4f162605939b24d23772696059d
MD5 c3f321a3926661c59e6082a960df97dc
BLAKE2b-256 91054744d0fc2be43e98f82db4aa9ea031b866d8ef4cf91c83cdc86cf6dc298f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sleigh_sdk-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 9.0 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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 e88db9cbe98fb1e394fe1f1631828a88d3336c34d9be123756b8205441b5c6fa
MD5 592fe4f2d223d6725ca04d7bd43c3b63
BLAKE2b-256 ad05401ecdeb8b2ee894470f2e09e5bd4094aaaf6280a60370011c822c0b91dd

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