Python SDK for Tenki Sandbox
Project description
Tenki Sandbox Python SDK
Python SDK for Tenki Sandbox: cloud sandboxes for AI agents and code execution.
pip install tenki-sandbox
from tenki_sandbox import Sandbox
with Sandbox.create(project_id="proj_123", cpu_cores=2, memory_mb=4096) as sb:
result = sb.exec("python3", "-c", "print('hello')")
result.check()
print(result.stdout_text)
# fs paths are relative to the sandbox workdir (absolute paths must stay inside it)
sb.fs.write_text("input.txt", "data")
print(sb.fs.read_text("input.txt"))
preview = sb.expose_port(3000, ttl=3600)
print(preview.url)
Auth
Auth resolution:
auth_token=passed toClientorSandbox.createTENKI_AUTH_TOKENTENKI_API_KEY
TENKI_API_ENDPOINT overrides the API URL; legacy TENKI_API_URL is also accepted.
Process API
exec collects stdout/stderr and returns a result:
result = sb.exec("npm", "test", timeout=60, env={"CI": "1"})
print(result.stdout_text)
result.check()
start returns a live process:
proc = sb.start("bash", "-lc", "read name; echo hello $name")
proc.write_stdin("tenki\n")
proc.close_stdin()
for chunk in proc.stdout:
print(chunk.decode(), end="")
proc.wait().check()
Use shell() when you want shell parsing:
sb.shell("python3 -m http.server 3000 >/tmp/server.log 2>&1 &")
Sandbox lifetime
Long-lived sandboxes are a parameter choice at create(), not a separate API:
sb = client.create(
project_id="proj_123",
sticky=True, # long-lived session: not reaped on idle
idle_timeout_minutes=120, # or: generous idle window before auto-pause
max_duration=8 * 3600, # total lifetime cap (seconds)
pause_retention=24 * 3600,# how long a paused session is kept resumable
)
max_durationcaps total lifetime;sb.extend(seconds)pushes the deadline (sb.info.timeout_at) while running.idle_timeout_minutesauto-pauses an idle sandbox;sb.resume()brings it back with the filesystem intact.sticky=Trueopts the session out of idle reaping for keep-warm use cases (workspaces cap concurrent sticky sessions).client.list(sticky=True)filters for long-lived sessions.
SSH
For tools that speak SSH (paramiko, scp, IDE remote dev), the SDK can mint a short-lived OpenSSH user certificate for your session and open a transport to the sandbox SSH gateway. No keys are provisioned into the guest; the engine signs your local public key and the gateway verifies the certificate.
Requires pip install websocket-client paramiko (websocket-client for the
transport, paramiko if you want a client in-process).
import subprocess
import paramiko
# 1. local keypair (any OpenSSH key works; ed25519 shown)
subprocess.run(["ssh-keygen", "-t", "ed25519", "-N", "", "-q", "-f", "id_tenki"], check=True)
# 2. engine signs a short-lived user cert for this sandbox
cert = sb.issue_ssh_cert(open("id_tenki.pub").read(), ttl=600)
open("id_tenki-cert.pub", "w").write(cert.ssh_cert)
# 3. open the gateway transport and run a paramiko session over it
pkey = paramiko.Ed25519Key.from_private_key_file("id_tenki")
pkey.load_certificate("id_tenki-cert.pub")
transport = paramiko.Transport(sb.ssh()) # WebSocket-backed socket
transport.connect(username="tenki", pkey=pkey)
session = transport.open_session()
session.exec_command("echo hello-over-ssh")
print(session.makefile().read().decode())
transport.close()
Notes:
sb.ssh()/client.ssh(session_id)discover an active gateway and returnSSHConn, anio.RawIOBasesocket usable anywhere paramiko accepts one.- The SSH username is
tenki. TENKI_SANDBOX_GATEWAY_URLoverrides the gateway WebSocket URL (it is otherwise derived from the API endpoint).- Certificate RPCs use the Connect protocol over HTTPS (same as the Go SDK and
the
tenkiCLI), so they work through standard HTTP load balancers. sb.update_ssh_authorized_keys([...])additionally plants long-lived public keys in the guest'sauthorized_keysif you prefer key-based auth for the in-guest sshd.
Resource APIs
from tenki_sandbox import Client, GiB
client = Client()
volume = client.volumes.create(
workspace_id="ws_123",
name="cache",
size_bytes=10 * GiB,
project_id="proj_123",
)
preview = client.preview_urls.create(
project_id="proj_123",
slug="demo",
session_id=sb.id,
port=3000,
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tenki_sandbox-0.1.1.tar.gz.
File metadata
- Download URL: tenki_sandbox-0.1.1.tar.gz
- Upload date:
- Size: 107.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2748d3cb381c1f955163b368189899517aa04f70e59d64fb06a999f400dfb0b6
|
|
| MD5 |
db3537e864ee700ada8a84e593292222
|
|
| BLAKE2b-256 |
357f6e59a084acece58d2349c80d95996cfc4971dcbc61038d6cc9a822edf3dc
|
Provenance
The following attestation bundles were made for tenki_sandbox-0.1.1.tar.gz:
Publisher:
pypi-publish.yml on TenkiCloud/tenki-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tenki_sandbox-0.1.1.tar.gz -
Subject digest:
2748d3cb381c1f955163b368189899517aa04f70e59d64fb06a999f400dfb0b6 - Sigstore transparency entry: 1777511429
- Sigstore integration time:
-
Permalink:
TenkiCloud/tenki-sdk-python@5081b504b665eb069f2b0ef9097faea16a4e95c1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/TenkiCloud
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
self-hosted -
Publication workflow:
pypi-publish.yml@5081b504b665eb069f2b0ef9097faea16a4e95c1 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file tenki_sandbox-0.1.1-py3-none-any.whl.
File metadata
- Download URL: tenki_sandbox-0.1.1-py3-none-any.whl
- Upload date:
- Size: 94.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
826ab21db80b3ebe74c9a67f3eeb09f8d880535677f8d5dc3d03ad402210f97c
|
|
| MD5 |
b61743f4dba0cb8f14d0af384ff243cd
|
|
| BLAKE2b-256 |
ef6b9e3a0eaf5064d47e3ec1115ba9585d117feb5507312e195d15ee9a9bba28
|
Provenance
The following attestation bundles were made for tenki_sandbox-0.1.1-py3-none-any.whl:
Publisher:
pypi-publish.yml on TenkiCloud/tenki-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tenki_sandbox-0.1.1-py3-none-any.whl -
Subject digest:
826ab21db80b3ebe74c9a67f3eeb09f8d880535677f8d5dc3d03ad402210f97c - Sigstore transparency entry: 1777511453
- Sigstore integration time:
-
Permalink:
TenkiCloud/tenki-sdk-python@5081b504b665eb069f2b0ef9097faea16a4e95c1 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/TenkiCloud
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
self-hosted -
Publication workflow:
pypi-publish.yml@5081b504b665eb069f2b0ef9097faea16a4e95c1 -
Trigger Event:
workflow_dispatch
-
Statement type: