Skip to Content
Python SDK

Python SDK

wasmer-sdk embeds Wasmer and WASIX in a Python application. Sandboxes run locally in the application process without Docker, a VM, or a remote sandbox service.

Install

python -m pip install wasmer-sdk

Published wheels support macOS and Linux on arm64 and x86_64. A wheel works across supported Python 3 versions on the same platform because the native boundary does not depend on the CPython ABI.

Run a package

main.py
import asyncio from wasmer_sdk import Wasmer async def main() -> None: wasmer = Wasmer() sandbox = await wasmer.sandboxes.create( packages=['python/python@=3.13.18'], files={ 'main.py': 'print(sum(n * n for n in range(10)))', }, ) output = await sandbox.command( 'python', ['/workspace/main.py'] ).run() print(output.text()) await sandbox.close() await wasmer.close() asyncio.run(main())

Constructing Wasmer() is synchronous. Operations that resolve packages, create sandboxes, or run commands are asynchronous. Reuse one client for multiple sandboxes. Call await sandbox.close() and await wasmer.close() when they are no longer needed. Both types also support async with when a context manager is more convenient.

run() captures a finite command and raises ProcessExitError when it exits unsuccessfully. Use spawn() for a long-running or interactive process with live asynchronous streams.

Compose software in one sandbox

The Python and JavaScript SDKs share the same package, sandbox, command, filesystem, and process model:

sandbox = await wasmer.sandboxes.create( packages=[ 'python/python@=3.13.18', 'wasmer/edgejs@0.2.0', 'php/php-32', ], ) python = await sandbox.command( 'python', ['-c', "print('Python')"] ).run() edgejs = await sandbox.command( 'node', ['-e', "console.log('Edge.js')"] ).run() php = await sandbox.command( 'php', ['-r', "echo 'PHP\\n';"] ).run() print(python.text(), edgejs.text(), php.text(), sep='')

Files passed to sandboxes.create() are written under /workspace. Use sandbox.fs to modify the filesystem while the sandbox is alive, or sandbox.install_package() to add software after creation.

Networking

Network access is disabled unless it is explicitly enabled:

sandbox = await wasmer.sandboxes.create( packages=['curl/curl'], network='host', )

The native SDK gives WASIX sockets access to the host network. Only enable it for sandboxes that need networking.

Registry metadata, downloaded packages, and compiled artifacts are cached in .wasmer by default. Pass cache_root='.cache/wasmer' to Wasmer() to use another location.

See the wasmer-sdk source and complete Python examples for process streams, Edge.js servers, and PostgreSQL.

Last updated on