Skip to main content

Airalogy protocol execute sandbox

Project description

airalogy-engine (Python)

PyPI version Python versions

Airalogy protocol execution sandbox for Python. Run protocol packages (parse, assign, validate) inside a secure BoxLite sandbox.

Installation

pip install airalogy-engine

Sandbox Image

The engine runs protocol code in a BoxLite sandbox. You can use either a remote Docker image or a local OCI rootfs directory.

Remote Image

from airalogy_engine import AiralogyEngine

engine = AiralogyEngine(image="numbcoder/airalogy-engine:0.1")
result = await engine.parse_protocol(protocol_path)

Local OCI Rootfs (Recommended)

Build and export the image locally for faster, offline execution:

docker build -t airalogy-engine:latest .
docker save airalogy-engine:latest -o airalogy-engine-image.tar
mkdir airalogy-engine-image
tar -xf airalogy-engine-image.tar -C airalogy-engine-image

Then use rootfs_path:

from airalogy_engine import AiralogyEngine

engine = AiralogyEngine(rootfs_path="./airalogy-engine-image")
result = await engine.parse_protocol(protocol_path)

If neither image nor rootfs_path is provided, the engine falls back to the default remote image numbcoder/airalogy-engine:latest.

Usage

import asyncio
from airalogy_engine import AiralogyEngine

async def main():
    protocol_path = "/path/to/your/protocol"
    rootfs_path = "/path/to/airalogy-engine-image"  # or use image="..." instead
    engine = AiralogyEngine(
        rootfs_path=rootfs_path,
        boxlite_home="/tmp/airalogy-engine-worker-1",
    )

    # 1. Parse the protocol
    result = await engine.parse_protocol(protocol_path, env_vars={"API_KEY": "xxx"})
    print(result["data"]["meta_data"])
    print(result["data"]["json_schema"])

    # 2. Assign a variable
    result = await engine.assign_variable(
        protocol_path,
        var_name="duration",
        dependent_data={"seconds": 3600},
        env_vars={"API_KEY": "xxx"},
    )
    print(result["data"])

    # 3. Validate variables
    result = await engine.validate_variables(
        protocol_path,
        variables={"seconds": 60, "duration": "PT1M"},
    )
    print(result["data"])

    await engine.close()

asyncio.run(main())

You can also use the engine as an async context manager:

async with AiralogyEngine(rootfs_path=rootfs_path, boxlite_home="/tmp/worker-1") as engine:
    result = await engine.parse_protocol(protocol_path)

API

API Description
AiralogyEngine(boxlite_home=None, image=None, rootfs_path=None, timeout=300, memory_mib=512, cpus=1) Create an engine bound to one BoxLite runtime home and sandbox configuration
engine.parse_protocol(protocol_path, env_vars=None, timeout=None, debug=False, log_file="protocol_debug.log") Parse a protocol and return schema, metadata, fields
engine.assign_variable(protocol_path, var_name, dependent_data, env_vars=None, timeout=None, debug=False, log_file="protocol_debug.log") Assign a variable using assigner functions
engine.validate_variables(protocol_path, variables, env_vars=None, timeout=None, debug=False, log_file="protocol_debug.log") Validate variable values against the protocol model
await engine.close() Release this engine's BoxLite runtime reference

All engine methods are async and return a dict with success, message, and data keys.

Engine parameters:

  • boxlite_home: BoxLite runtime home directory. Use a distinct value for each OS process when running multiple workers.
  • image: Remote Docker image name (e.g., "numbcoder/airalogy-engine:0.1").
  • rootfs_path: Path to a local OCI rootfs directory (overrides image).
  • timeout: Execution timeout in seconds (default: 300). The sandboxed process will be killed once it times out.
  • memory_mib: Memory limit in MiB (default: 512).
  • cpus: CPU limit (default: 1).

Concurrency

Use one AiralogyEngine instance per worker process and run concurrent operations through that object:

engine = AiralogyEngine(rootfs_path=rootfs_path, boxlite_home="/tmp/worker-1")

results = await asyncio.gather(
    engine.parse_protocol(protocol_a),
    engine.parse_protocol(protocol_b),
)

BoxLite locks each runtime home per OS process. Two independent processes must not share the same boxlite_home or default ~/.boxlite; give each process a distinct directory, for example /tmp/airalogy-worker-1 and /tmp/airalogy-worker-2.

Testing

cd python
uv sync

# Default: local OCI rootfs mode
uv run pytest tests/ -v

# Custom rootfs path
uv run pytest tests/ -v --sandbox-mode=rootfs --rootfs-path=../airalogy-engine-0.1

# Remote image mode
uv run pytest tests/ -v --sandbox-mode=image --sandbox-image=numbcoder/airalogy-engine:0.1

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

airalogy_engine-0.0.3.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

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

airalogy_engine-0.0.3-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file airalogy_engine-0.0.3.tar.gz.

File metadata

  • Download URL: airalogy_engine-0.0.3.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for airalogy_engine-0.0.3.tar.gz
Algorithm Hash digest
SHA256 faf2d424525e62007b4c0c9c6eff8535409b06dedd110795d0bda87c015acf45
MD5 960c2f51283b3df293319c5191813212
BLAKE2b-256 7da7455199bca5582020158d43b49f8b25c2c4c4c3b6ed66e06f99fb0f2e20e2

See more details on using hashes here.

File details

Details for the file airalogy_engine-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: airalogy_engine-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for airalogy_engine-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7e8a79f081f757d588cc52a60cc223b7b7fdba1313a743939a77173ae7560b83
MD5 c4753576e4b3c9772281f99883db437b
BLAKE2b-256 6f616f0f0a008314caa0d5ebfc49c1e6e564785af5f0394eee3e3cb87d50afcb

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