Python SDK for agentkernel — run AI coding agents in secure, isolated microVMs
Project description
agentkernel
Python SDK for agentkernel — run AI coding agents in secure, isolated microVMs.
Install
pip install agentkernel-sdk
Requires Python 3.10+.
Quick Start
from agentkernel import AgentKernel
with AgentKernel() as client:
result = client.run(["echo", "hello"])
print(result.output) # "hello\n"
Async
from agentkernel import AsyncAgentKernel
async with AsyncAgentKernel() as client:
result = await client.run(["echo", "hello"])
print(result.output)
Sandbox Sessions
with AgentKernel() as client:
with client.sandbox("test", image="python:3.12-alpine") as sb:
sb.run(["pip", "install", "numpy"])
result = sb.run(["python3", "-c", "import numpy; print(numpy.__version__)"])
print(result.output)
# sandbox auto-removed
Exec Options
Run commands with a working directory, environment variables, or as root:
with AgentKernel() as client:
result = client.exec_in_sandbox(
"my-sandbox",
["npm", "start"],
workdir="/app",
env=["NODE_ENV=production"],
sudo=True,
)
Works on sandbox sessions too:
with client.sandbox("dev") as sb:
sb.run(["pip", "install", "-r", "requirements.txt"], workdir="/app", sudo=True)
Git Source Cloning
Clone a git repo into the sandbox at creation time:
with AgentKernel() as client:
client.create_sandbox(
"my-project",
image="node:20-alpine",
source_url="https://github.com/user/repo.git",
source_ref="main",
)
Persistent Volumes
Mount volumes that persist across sandbox restarts:
# First create volumes via CLI: agentkernel volume create mydata
with AgentKernel() as client:
client.create_sandbox(
"my-project",
image="python:3.12-alpine",
volumes=["mydata:/data", "cache:/tmp/cache:ro"],
)
# Data in /data persists across sandbox restarts
client.exec_in_sandbox("my-project", ["sh", "-c", "echo hello > /data/test.txt"])
File Operations
Read, write, and delete files in a sandbox:
with AgentKernel() as client:
# Write a file
client.write_file("my-sandbox", "app/main.py", "print('hello')")
# Read a file
file = client.read_file("my-sandbox", "app/main.py")
print(file.content)
# Delete a file
client.delete_file("my-sandbox", "app/main.py")
# Batch write multiple files at once
client.write_files("my-sandbox", {
"/app/index.js": "console.log('hi')",
"/app/package.json": '{"name":"app"}',
})
Detached Commands
Run long-lived processes in the background and retrieve their output later:
with AgentKernel() as client:
# Start a background process
cmd = client.exec_detached("my-sandbox", ["python3", "train.py"])
print(f"Started: {cmd.id} (pid {cmd.pid})")
# Check status
status = client.detached_status("my-sandbox", cmd.id)
print(status.status) # "running" | "completed" | "failed"
# Get logs
logs = client.detached_logs("my-sandbox", cmd.id)
print(logs.stdout)
# Get stderr only
stderr = client.detached_logs("my-sandbox", cmd.id, stream="stderr")
# List all detached commands
all_cmds = client.detached_list("my-sandbox")
# Kill a running command
client.detached_kill("my-sandbox", cmd.id)
Async version:
async with AsyncAgentKernel() as client:
cmd = await client.exec_detached("my-sandbox", ["python3", "train.py"])
logs = await client.detached_logs("my-sandbox", cmd.id)
Streaming
for event in client.run_stream(["python3", "script.py"]):
if event.type == "output":
print(event.data["data"], end="")
Configuration
client = AgentKernel(
base_url="http://localhost:18888", # default
api_key="sk-...", # optional
timeout=30.0, # default
)
Or use environment variables:
export AGENTKERNEL_BASE_URL=http://localhost:18888
export AGENTKERNEL_API_KEY=sk-...
License
MIT
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 agentkernel_sdk-0.13.0.tar.gz.
File metadata
- Download URL: agentkernel_sdk-0.13.0.tar.gz
- Upload date:
- Size: 54.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ea5ffbadf79acb684b1f2a5c50e20ff1240d487926dec3ba19730d6a978a0f6
|
|
| MD5 |
9bd5983de5f69801ee15a2033663917b
|
|
| BLAKE2b-256 |
9030b79d21723a79fafadaec30f62e189d729db0986b85aff4b0bb6c9e2cba2d
|
Provenance
The following attestation bundles were made for agentkernel_sdk-0.13.0.tar.gz:
Publisher:
sdk-publish.yml on thrashr888/agentkernel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agentkernel_sdk-0.13.0.tar.gz -
Subject digest:
1ea5ffbadf79acb684b1f2a5c50e20ff1240d487926dec3ba19730d6a978a0f6 - Sigstore transparency entry: 947103462
- Sigstore integration time:
-
Permalink:
thrashr888/agentkernel@69eedfd93ef046a13b35472684bd743e7614b2bd -
Branch / Tag:
refs/tags/v0.13.0 - Owner: https://github.com/thrashr888
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk-publish.yml@69eedfd93ef046a13b35472684bd743e7614b2bd -
Trigger Event:
push
-
Statement type:
File details
Details for the file agentkernel_sdk-0.13.0-py3-none-any.whl.
File metadata
- Download URL: agentkernel_sdk-0.13.0-py3-none-any.whl
- Upload date:
- Size: 21.5 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 |
d094523b09f8983b4a5f6d5b9d7c2e6223a54f8c9d9951113fe27dace381d41e
|
|
| MD5 |
c4b7a2ca3ea8c653358d9dae37f5eb1e
|
|
| BLAKE2b-256 |
6dee7245e168e9cea038e9abbe4560e3be2bdec1c5c5aa46c9140fc4808cda01
|
Provenance
The following attestation bundles were made for agentkernel_sdk-0.13.0-py3-none-any.whl:
Publisher:
sdk-publish.yml on thrashr888/agentkernel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agentkernel_sdk-0.13.0-py3-none-any.whl -
Subject digest:
d094523b09f8983b4a5f6d5b9d7c2e6223a54f8c9d9951113fe27dace381d41e - Sigstore transparency entry: 947103474
- Sigstore integration time:
-
Permalink:
thrashr888/agentkernel@69eedfd93ef046a13b35472684bd743e7614b2bd -
Branch / Tag:
refs/tags/v0.13.0 - Owner: https://github.com/thrashr888
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk-publish.yml@69eedfd93ef046a13b35472684bd743e7614b2bd -
Trigger Event:
push
-
Statement type: