Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sandflare_autogen-0.1.3.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

sandflare_autogen-0.1.3-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file sandflare_autogen-0.1.3.tar.gz.

File metadata

  • Download URL: sandflare_autogen-0.1.3.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

Hashes for sandflare_autogen-0.1.3.tar.gz
Algorithm Hash digest
SHA256 1a24d572f750f214708222aacf494190d8def18697e3c8eb4ae9e0cd713c89ce
MD5 3b103e3e75baf42f1503268ba5c353f5
BLAKE2b-256 9bb81bd4b013d6f8a4d61baa06456094bfb1f4a9678728cf7b86a56d67d1a83b

See more details on using hashes here.

File details

Details for the file sandflare_autogen-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for sandflare_autogen-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4d1fa9e20d9a47c9b7134d0b40108126777649ba1f3fb6d9d1fff16a8c13b9a2
MD5 b408a6e7a6d91b2993175a6c7ccf3415
BLAKE2b-256 282fc29bf7d74cc656a6efd92f9d5e4b60847b4d93cb2aca0f83890db79347d3

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