AutoGen code executor for Sandflare Firecracker microVM sandboxes — run agent-generated code safely
Project description
sandflare-autogen
AutoGen CodeExecutor that runs agent-generated code in isolated Sandflare Firecracker microVM sandboxes.
Installation
pip install sandflare-autogen
Usage
Basic — SandflareCodeExecutor
Each execute_code_blocks() call runs in the same sandbox. The sandbox is destroyed when stop() is called or the context manager exits.
from sandflare_autogen import SandflareCodeExecutor
from autogen.coding import CodeBlock
with SandflareCodeExecutor(api_key="pa_live_...") as executor:
result = executor.execute_code_blocks([
CodeBlock(code="print('hello from Firecracker!')", language="python")
])
print(result.output)
# hello from Firecracker!
Set SANDFLARE_API_KEY in your environment to omit the api_key argument.
Persistent State — SandflarePersistentExecutor
Variables, imports, and installed packages are preserved between calls via a persistent Jupyter kernel.
from sandflare_autogen import SandflarePersistentExecutor
from autogen.coding import CodeBlock
with SandflarePersistentExecutor() as executor:
executor.execute_code_blocks([
CodeBlock(code="import numpy as np\nx = np.array([1, 2, 3])", language="python")
])
result = executor.execute_code_blocks([
CodeBlock(code="print(x.mean())", language="python")
])
print(result.output) # 2.0
ConversableAgent Example
from sandflare_autogen import SandflareCodeExecutor
from autogen import ConversableAgent
with SandflareCodeExecutor(api_key="pa_live_...") as executor:
agent = ConversableAgent(
name="coder",
llm_config={"model": "gpt-4o", "api_key": "sk-..."},
code_execution_config={"executor": executor},
)
user = ConversableAgent(
name="user",
human_input_mode="NEVER",
is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"),
)
user.initiate_chat(
agent,
message="Write Python code to find the 50th prime number. Reply TERMINATE when done.",
)
Constructor Options
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key |
str |
env var | Sandflare API key (SANDFLARE_API_KEY) |
template_id |
str |
"" |
Sandbox template ID (empty = base Ubuntu + Python 3) |
size |
str |
"small" |
VM size: nano, small, medium, large, xl |
timeout |
int |
60 |
Per-execution timeout in seconds |
persistent |
bool |
False |
Preserve sandbox state across restart() calls |
base_url |
str |
None |
Override API base URL (self-hosted deployments) |
env |
dict |
{} |
Environment variables injected into the sandbox |
Docs
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 sandflare_autogen-0.1.1.tar.gz.
File metadata
- Download URL: sandflare_autogen-0.1.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f59c714228b0bb3a1c5ea27fde517cc7ed2e19481c812d350562e56d0dd8818
|
|
| MD5 |
8d43c0f44b606a650a66b2a29403a3a6
|
|
| BLAKE2b-256 |
04a7109250ea9dd71962e83d8777bf53365bc8193481c35a5db0f4cbaa94e932
|
File details
Details for the file sandflare_autogen-0.1.1-py3-none-any.whl.
File metadata
- Download URL: sandflare_autogen-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
406e343813929add26cfd8a8b8fb2efe20f2ae709fee50471dd65bfa3edfc093
|
|
| MD5 |
1eef16ae617661f26c63af62b7676f5c
|
|
| BLAKE2b-256 |
aeefb73c36693868e2d81768f3e8ca5a0f8bb8cd726a1b3489448ad4da53efa0
|