Skip to main content

Python SDK for FireVM SaaS - Execute code in isolated Firecracker VMs

Project description

FireVM Python SDK

Official Python client for executing code in isolated Firecracker VMs.

Installation

pip install firevm-sdk

Or install from source:

cd sdk/python
pip install -e .

Quick Start

from firevm_sdk import FireVMClient

# Initialize client with your API key
client = FireVMClient(api_key="your_api_key_here")

# Create a VM
vm = client.create_vm(name="my-vm")
print(f"VM created: {vm.vm_id}")

# Execute Python code
result = client.execute_python(vm.vm_id, """
print("Hello from FireVM!")
print(f"2 + 2 = {2 + 2}")
""")

print(result.stdout)  # Hello from FireVM!\n2 + 2 = 4
print(result.exit_code)  # 0

Examples

Execute Python Code

result = client.execute_python(vm.vm_id, "print('Hello World')")
print(result.stdout)  # Hello World

Execute Bash Commands

result = client.execute_bash(vm.vm_id, "ls -la && whoami")
print(result.stdout)

Handle Errors

result = client.execute_python(vm.vm_id, "1/0")
if result.exit_code != 0:
    print(f"Error: {result.stderr}")

Multiple Languages

# Python
client.execute(vm.vm_id, "print('Python!')", language="python")

# Bash
client.execute(vm.vm_id, "echo 'Bash!'", language="bash")

# Node.js
client.execute(vm.vm_id, "console.log('JavaScript!')", language="nodejs")

Error Handling

VM Quota Exceeded

When you reach your VM limit, the SDK raises a VMQuotaExceeded exception:

from firevm_sdk import FireVMClient, VMQuotaExceeded

client = FireVMClient(api_key="your_key")

try:
    vm = client.create_vm("my-vm")
except VMQuotaExceeded as e:
    print(f"❌ {e.message}")
    print(f"   Current VMs: {e.current_vms}/{e.max_vms}")
    print(f"   Your tier: {e.tier}")
    print(f"   Suggested: Stop unused VMs or upgrade your tier")

Tier Limits

  • Free tier: 5 concurrent VMs, auto-stop after 10min idle
  • Paid tier: 10 concurrent VMs, auto-stop after 10min idle
  • Pro tier: 20 concurrent VMs, auto-stop after 10min idle
  • Enterprise: 999 concurrent VMs, auto-stop after 10min idle

Upgrade at: https://firevm-frontend-345160625255.asia-northeast1.run.app/pricing

API Reference

FireVMClient

FireVMClient(api_key: str, base_url: str = "https://firevm-backend-345160625255.asia-northeast1.run.app")

Initialize the FireVM client.

create_vm()

create_vm(name: str, tier: str = "small", wait: bool = True) -> VM

Create a new VM instance.

Parameters:

  • name: VM name
  • tier: VM size ("small", "medium", "large")
  • wait: Wait for VM to be ready (default: True)

execute()

execute(vm_id: str, code: str, language: str = "python", timeout: int = 30, wait: bool = True) -> ExecutionResult

Execute code in a VM.

Parameters:

  • vm_id: VM identifier
  • code: Code to execute
  • language: "python", "bash", or "nodejs"
  • timeout: Execution timeout in seconds
  • wait: Wait for execution to complete

Returns: ExecutionResult with:

  • stdout: Standard output
  • stderr: Standard error
  • exit_code: Exit code (0 = success)
  • execution_time: Time taken in seconds
  • error: Error message if any

Get Your API Key

  1. Visit https://firevm-frontend-345160625255.asia-northeast1.run.app
  2. Sign up for an account
  3. Copy your API key from the dashboard

Support

License

MIT License - see LICENSE file for details.

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

firevm_sdk-0.1.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

firevm_sdk-0.1.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file firevm_sdk-0.1.1.tar.gz.

File metadata

  • Download URL: firevm_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for firevm_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c09899ff13fe6b63820f6ca64a996736d5ef2af1e8b841e88ec05bd46ebac8fb
MD5 fb34b6dae7fdf22efde91125c2ccc369
BLAKE2b-256 ad72e4f7c7a1cd0a36aace057cbb482427c26e8bc49e3f015a107fb8c17b9a46

See more details on using hashes here.

File details

Details for the file firevm_sdk-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: firevm_sdk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for firevm_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bd9746c9487f4811900c890d07cf915d26f47edba18426c04aba68c73d203b36
MD5 d6d1cc4caf948f3dd5c5e30bd983a84a
BLAKE2b-256 925638c8f7edbf221e8a0a1ec39bf4a3c2289005276928e27faa1221fc19aa14

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