Skip to main content

A WASMTIME-based Python code executor for smolagents with sandboxed execution

Project description

WASMTIME Executor for CodeAgent

A secure Python code executor for smolagents that uses WASMTIME WebAssembly runtime with the real python.wasm binary to provide strong isolation guarantees.

Usage

You can use it as a drop-in replacement for the built-in PythonExecutor in smolagents. The example is in examples/smolagents_wasmtime.py.

from wasmtime_executor import WasmtimePythonExecutor

from smolagents import CodeAgent, InferenceClientModel
from smolagents.local_python_executor import PythonExecutor


class WasmtimeCodeAgent(CodeAgent):
    """
    Custom CodeAgent that uses WasmtimePythonExecutor for code execution.

    This agent extends the standard CodeAgent to support WASMTIME-based
    WebAssembly execution for enhanced security and isolation.
    """

    def create_python_executor(self) -> PythonExecutor:
        """Override to use WasmtimePythonExecutor instead of built-in executors."""
        return WasmtimePythonExecutor(
            additional_authorized_imports=self.additional_authorized_imports,
            max_print_outputs_length=self.max_print_outputs_length,
            **self.executor_kwargs,
        )


def main():
    model = InferenceClientModel()

    additional_authorized_imports = ["math", "json"]
    max_print_outputs_length = 1000

    agent = WasmtimeCodeAgent(
        tools=[],
        model=model,
        additional_authorized_imports=additional_authorized_imports,
        max_print_outputs_length=max_print_outputs_length,
    )

    output = agent.run("Calculate the square root of 125 and explain the result.")
    print("WASMTIME executor result:", output)

Acknowledgments

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

wasmtime_executor-0.1.0.tar.gz (9.1 MB view details)

Uploaded Source

Built Distribution

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

wasmtime_executor-0.1.0-py3-none-any.whl (9.2 MB view details)

Uploaded Python 3

File details

Details for the file wasmtime_executor-0.1.0.tar.gz.

File metadata

  • Download URL: wasmtime_executor-0.1.0.tar.gz
  • Upload date:
  • Size: 9.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.14

File hashes

Hashes for wasmtime_executor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 543b834628aa405f1bf99793b7046067cf30ecce758e343f5e56a2740a04eb51
MD5 1e2cecf06da29e023f150ba7c229690b
BLAKE2b-256 0a0e373298279e8dcf99b136f00ca434efefc2db070334273afb978b07ecf047

See more details on using hashes here.

File details

Details for the file wasmtime_executor-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wasmtime_executor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a5ea6d25fd49d2d5c0714ffcf44693895faf4c92a5299427a6dccfbab964a6a
MD5 60083575aa773877facab265a6ee3671
BLAKE2b-256 fe7be4b3d3127ebd30b72dd74e618a08b29421fe9c236387b15effbb3e2c5aba

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