Skip to main content

Python SDK for Kanyun Sandbox v2 control plane

Project description

Kanyun Sandbox Python SDK

Python SDK for the Kanyun Sandbox v2 control plane.

The SDK is image-agnostic by default. It can create, query, list, and delete sandboxes for any configured template. Agent access is optional and requires an explicit agent_client_factory for images that expose a compatible agent service.

Install

cd sdk/python
pip install .
  • package name: kanyun-sandbox
  • import: kanyun_sandbox

Quick Start

from kanyun_sandbox import Client

client = Client(
    control_plane_url="http://127.0.0.1:8080",
    api_key="kanyun_xxx",
)

with client.run_session(template_name="python-dev", ttl_seconds=300) as session:
    print(session.info.claim_name or session.info.sandbox_name)

Client

client = Client(
    control_plane_url="http://127.0.0.1:8080",
    api_key="kanyun_xxx",
    agent_port=8080,
    agent_client_factory=None,
)

Implemented methods:

  • create_sandbox(request)
  • get_sandbox(id)
  • list_sandboxes()
  • get_sandbox_detail(id)
  • list_sandbox_events(id)
  • delete_sandbox(id)
  • connect_sandbox(id)
  • new_session(request)
  • run_session(...)
  • list_templates()
  • get_template(name)
  • apply_template(name, request) / delete_template(name)
  • list_template_materializations(name) / resync_template_materialization(name)
  • list_warm_pools() / get_warm_pool(name) / apply_warm_pool(name, request) / delete_warm_pool(name)
  • list_sandbox_history(...) / get_sandbox_history(id)
  • Platform profile helpers for clusters, runtime profiles, build profiles, registry profiles, secret profiles, secret materializations, rotate, and resync
  • Image build and asset helpers for builds, logs, cancellation, and reusable image assets

SandboxInfo.public_endpoints is populated when templates define ingress blueprints.

Optional Agent Adapter

If your template image runs a compatible agent service, install that client separately and pass a factory:

from agent_sandbox import Sandbox
from kanyun_sandbox import Client

client = Client(
    control_plane_url="http://127.0.0.1:8080",
    api_key="kanyun_xxx",
    agent_client_factory=lambda base_url: Sandbox(base_url=base_url),
)

with client.run_session(template_name="agent-enabled-devbox", ttl_seconds=300) as session:
    result = session.agent.shell.exec_command(command="pwd")
    print(result)

Agent clients are created lazily. Creating or connecting a sandbox does not require agent support. Accessing handle.agent or session.agent without a factory raises SandboxAgentUnavailableError; accessing agent before an IP is available raises SandboxNotReadyError.

Authentication

All control-plane requests use X-API-Key.

Agent Connection Rule

When agent access is enabled:

  1. Read SandboxInfo.ip.
  2. Build http://{ip}:8080, or use the configured agent_port.
  3. Do not fall back to endpoint.

Migration Notes

The v2 SDK keeps the familiar Client, SandboxHandle, Session, and run_session(...) flow. Unlike the old SDK, .agent is not assumed to exist for every sandbox. Use control-plane methods for generic images, and opt into .agent only for templates whose image implements the expected agent protocol.

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

kanyun_sandbox-0.3.0.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

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

kanyun_sandbox-0.3.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file kanyun_sandbox-0.3.0.tar.gz.

File metadata

  • Download URL: kanyun_sandbox-0.3.0.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for kanyun_sandbox-0.3.0.tar.gz
Algorithm Hash digest
SHA256 14d3c5fdb9c9a06e608db43ab9e53e87b0137af977c781d49c56a526522ba3b6
MD5 f2b48f285763e636efc1d306abc0f4cc
BLAKE2b-256 5a8e2db64cddf0828e9429e75b272b7ae1733fbfe6386d1551c3521889aa06b1

See more details on using hashes here.

File details

Details for the file kanyun_sandbox-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: kanyun_sandbox-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for kanyun_sandbox-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 23024a053fec4c96d58f31df6d05b7532236580f2b6b79d38c25445d74e9dcb7
MD5 12ce7740a7b0107226728921e10ea506
BLAKE2b-256 3183177abfe09ebd3b8d30b8e7f6f560b21045feaefcf23d5c96bce6352191a4

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