Skip to main content

Process-isolated networked Lua VMs with multi-VM support and XCP-ng integration

Project description

pylua_bioxen_vm_lib

A Python library for orchestrating networked Lua virtual machines through subprocess management and socket communication with multi-VM support.

Overview

pylua_bioxen_vm_lib provides a unique approach to running multiple Lua interpreters as isolated processes, managed from Python with built-in networking capabilities. Version 0.1.19 introduces Phase 1 multi-VM support with factory pattern for different VM types including XCP-ng integration placeholders.

Key Features

  • Multi-VM Architecture - Factory pattern supporting different VM types (basic, xcpng)
  • Process-isolated Lua VMs - Each VM runs in its own subprocess for fault tolerance
  • XCP-ng Integration - Phase 1 placeholder support for XCP-ng VMs (full implementation in Phase 2)
  • Built-in networking - Socket-based communication using LuaSocket
  • Multiple communication patterns - Server, client, and P2P messaging modes
  • Dynamic VM management - Spawn and terminate VMs as needed
  • Language-agnostic architecture - Could be extended to other interpreters
  • Python orchestration - Full lifecycle management from Python
  • Interactive sessions - Attach/detach to running VMs for real-time interaction
  • Backward compatibility - All existing code works unchanged

Interactive Terminal Support

pylua_bioxen_vm_lib now supports interactive session management, allowing you to attach to running Lua VMs and interact with them in real-time.

Interactive Session Management

  • Attach/detach to running Lua VMs
  • Send input and receive output in real-time
  • Session lifecycle management
  • Multiple concurrent sessions per VM

Example Usage

from pylua_bioxen_vm_lib import VMManager, InteractiveSession

manager = VMManager()
vm = manager.create_vm("interactive_vm")

# Start an interactive session
session = InteractiveSession(vm)
session.attach()

# Send commands and get responses
session.send_input("x = 42")
session.send_input("print(x)")
output = session.read_output()

# Detach when done
session.detach()

Multi-VM Support (Phase 1)

from pylua_bioxen_vm_lib import create_vm, VMManager

# Create different types of VMs
basic_vm = create_vm("basic_worker", vm_type="basic")
xcpng_vm = create_vm("xcpng_worker", vm_type="xcpng", config={
    "xcpng_host": "192.168.1.100",
    "username": "root", 
    "password": "secret",
    "template": "lua-bio-template"
})

# Use VMManager for coordinated operations
with VMManager() as manager:
    basic = manager.create_vm("basic", vm_type="basic")
    xcpng = manager.create_vm("xcpng", vm_type="xcpng", config=config)
    
    # Get VM info
    info = manager.get_vm_info("xcpng")
    print(f"VM Type: {info['vm_type']}")  # xcpng

Architecture

Python Process
├── VM Manager
│   ├── Lua Process 1 (subprocess)
│   ├── Lua Process 2 (subprocess)
│   └── Lua Process N (subprocess)
└── Networking Layer
    ├── Socket Server
    ├── Socket Client
    └── P2P Communication

Installation

pip install pylua_bioxen_vm_lib

Prerequisites

  • Python 3.7+
  • Lua interpreter installed on system
  • LuaSocket library (luarocks install luasocket)

Quick Start

from pylua_bioxen_vm_lib import VMManager

# Create a VM manager
manager = VMManager()

# Spawn Lua VMs
vm1 = manager.create_vm("vm1")
vm2 = manager.create_vm("vm2")

# Execute Lua code
result = vm1.execute("return math.sqrt(16)")
print(result)  # 4.0

# Enable networking
vm1.start_server(port=8080)
vm2.connect_to("localhost", 8080)

# Send messages between VMs
vm2.send_message("Hello from VM2!")
message = vm1.receive_message()

# Cleanup
manager.shutdown_all()

Use Cases

  • Distributed computing - Parallel Lua script execution
  • Game servers - Isolated game logic processes
  • Microservices - Lightweight Lua-based services
  • Sandboxed scripting - Safe execution of untrusted Lua code
  • Load balancing - Multiple worker processes
  • Protocol testing - Network protocol simulation

Communication Patterns

Server Mode

vm.start_server(port=8080)
vm.accept_connections()

Client Mode

vm.connect_to("hostname", port)
vm.send_data("message")

P2P Mode

vm1.establish_p2p_with(vm2)
vm1.broadcast("Hello network!")

example usage

from pylua_bioxen_vm_lib import VMManager

with VMManager() as manager:
    # Server VM
    server_vm = manager.create_vm("server", networked=True)
    server_future = manager.start_server_vm("server", port=8080)
    
    # Client VM  
    client_vm = manager.create_vm("client", networked=True)
    client_future = manager.start_client_vm("client", "localhost", 8080, "Hello!")
    
    # P2P VM
    p2p_vm = manager.create_vm("p2p", networked=True)
    p2p_future = manager.start_p2p_vm("p2p", 8081, "localhost", 8080)

Examples

See the examples/ directory for:

  • Basic VM management (basic_usage.py)
  • Distributed computation (distributed_compute.py)
  • P2P messaging (p2p_messaging.py)

Documentation

Development

git clone https://github.com/yourusername/pylua_bioxen_vm_lib.git
cd pylua_bioxen_vm_lib
pip install -e .
python -m pytest tests/

Contributing

Contributions welcome! Please read our contributing guidelines and submit pull requests.

License

MIT License - see LICENSE file for details.

Why pylua_bioxen_vm_lib?

Existing Python-Lua integrations focus on embedding Lua within Python processes. pylua_bioxen_vm_lib takes a different approach by managing separate Lua processes, providing:

  • True isolation - One VM crash doesn't affect others
  • Horizontal scaling - Easy to distribute across cores/machines
  • Network-first design - Built for distributed systems
  • Fault tolerance - Automatic recovery and reconnection
  • Resource management - Independent memory and CPU usage per VM

Perfect for applications requiring robust, scalable Lua script execution with network communication capabilities.

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

pylua_bioxen_vm_lib-0.1.22.tar.gz (116.9 kB view details)

Uploaded Source

Built Distribution

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

pylua_bioxen_vm_lib-0.1.22-py3-none-any.whl (55.5 kB view details)

Uploaded Python 3

File details

Details for the file pylua_bioxen_vm_lib-0.1.22.tar.gz.

File metadata

  • Download URL: pylua_bioxen_vm_lib-0.1.22.tar.gz
  • Upload date:
  • Size: 116.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for pylua_bioxen_vm_lib-0.1.22.tar.gz
Algorithm Hash digest
SHA256 1278b1f565f4e905883049d312adefd359c8c9842826d4f725efb04e07e3b646
MD5 e56b7d7cb35b9c8d09abf38930d6f61f
BLAKE2b-256 7135d9fb58ecf58a01861152bfc73d87080fe0b92fbdc64f31b7da5e8874bebd

See more details on using hashes here.

File details

Details for the file pylua_bioxen_vm_lib-0.1.22-py3-none-any.whl.

File metadata

File hashes

Hashes for pylua_bioxen_vm_lib-0.1.22-py3-none-any.whl
Algorithm Hash digest
SHA256 dff74ce9af2b6897b09e7c08cec310c4fa2f58725076793802c56ebf0f52c57d
MD5 3420fbce8ab803b665bdbf4b296356c3
BLAKE2b-256 19843ea1fab171b600025a09aa72df60dcba86ff0b9f02614a4d048160f17f93

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