Plugin runtime environment for Spec-Kit - Plugin container, message bus, and sandbox
Project description
spec-kit-runtime
Plugin runtime environment for the Spec-Kit ecosystem.
Overview
This package provides the runtime infrastructure for loading, managing, and executing plugins in the Spec-Kit ecosystem. It includes:
- Plugin Container: Manages plugin lifecycle (discovery → load → activate → deactivate → unload)
- Message Bus: Pattern-based message routing with scoped delivery
- Plugin Sandbox: Restricted execution environment for untrusted plugins
- Service Provider: Dependency injection for plugin services
- Security: Path validation, input sanitization, code security
Installation
pip install spec-kit-runtime
Key Components
PluginContainer
Manages complete plugin lifecycle:
from spec_kit_runtime import PluginContainer
from pathlib import Path
# Create container
container = PluginContainer()
# Discover plugins
plugins = container.discover_plugins([
Path(".specify/plugins"),
Path("~/.specify/plugins").expanduser(),
])
# Load a plugin
plugin_info = container.discovered_plugins["design"]
container.load_plugin(plugin_info, config={"enabled": True})
# Activate
container.activate_plugin("design")
# Use plugin (via message bus)
result = container.send_message("design", command_message)
# Cleanup
container.shutdown()
ScopedMessageBus
Pattern-based message routing with plugin isolation:
from spec_kit_runtime import ScopedMessageBus
bus = ScopedMessageBus()
bus.start()
# Register plugin scope
bus.register_scope("design", [
"command:design:*",
"event:system:*",
])
# Subscribe to patterns
bus.subscribe_scoped("design", "command:design:generate", handler)
# Send messages
bus.send_scoped("design", command_message)
bus.stop()
PluginSandbox
Restricted execution environment:
from spec_kit_runtime import PluginSandbox
sandbox = PluginSandbox(
allowed_imports=["json", "datetime", "pathlib"],
restricted_builtins=["eval", "exec", "open"],
)
# Load plugin in sandbox
plugin = sandbox.load_plugin(plugin_info, config)
ServiceProvider
Dependency injection for plugins:
from spec_kit_runtime import ServiceProvider
provider = ServiceProvider()
# Register services
provider.register_service("plugin-id", IFileSystemService, fs_impl)
provider.register_service("plugin-id", IConfigService, config_impl)
# Get services
fs = provider.get_service(IFileSystemService)
Plugin Loading Modes
Normal Mode (sandbox=false)
- Direct Python import
- Full access to allowed modules
- Fastest execution
- Use for trusted plugins
Sandboxed Mode (sandbox=true, default)
- RestrictedImporter limits imports
- RestrictedBuiltins blocks dangerous functions
- AST validation detects dangerous patterns
- Use for untrusted plugins
Process-Isolated Mode (process_isolated=true)
- Separate Python process
- IPC communication
- Maximum isolation
- Use for completely untrusted plugins
Security Features
Import Restrictions
- 60+ dangerous modules blocked (os, subprocess, socket, etc.)
- Whitelist of safe standard library modules
- No dynamic import tricks allowed
Builtin Restrictions
- eval, exec blocked
- open blocked (use IFileSystemService instead)
- compile, import restricted
AST Validation
- Detects dangerous code patterns
- Blocks metaclass manipulation
- Prevents attribute access exploits
Path Security
- Path traversal protection
- Plugin ID sanitization
- Version format validation
Message Patterns
Plugins communicate via message patterns:
| Pattern | Example | Description |
|---|---|---|
command:{plugin}:{action} |
command:design:generate |
Execute action |
event:{plugin}:{name} |
event:design:completed |
Notification |
request:{plugin}:{method} |
request:config:get |
Request/response |
generator:{name} |
generator:hld |
Content generation |
validator:{name} |
validator:python |
Validation |
hook:{name} |
hook:post_save |
Lifecycle hook |
Architecture
┌─────────────────────────────────────────────────┐
│ PluginContainer │
│ ┌───────────┐ ┌───────────┐ ┌───────────┐ │
│ │ Discovery │ │ Loader │ │ Lifecycle │ │
│ └─────┬─────┘ └─────┬─────┘ └─────┬─────┘ │
│ │ │ │ │
│ ┌─────┴──────────────┴──────────────┴─────┐ │
│ │ ScopedMessageBus │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
│ │ │ Scope A │ │ Scope B │ │ Scope C │ │ │
│ │ └─────────┘ └─────────┘ └─────────┘ │ │
│ └──────────────────────────────────────────┘ │
│ │ │
│ ┌────────────────────┴────────────────────┐ │
│ │ ServiceProvider │ │
│ │ ┌─────────────────────────────────┐ │ │
│ │ │ Plugin Services (per-plugin) │ │ │
│ │ └─────────────────────────────────┘ │ │
│ └──────────────────────────────────────────┘ │
└─────────────────────────────────────────────────┘
Dependencies
spec-kit-contracts>=1.0.0- Interface contractspyyaml>=6.0- Configuration parsing
License
MIT License - see LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spec_kit_runtime-1.0.0.tar.gz.
File metadata
- Download URL: spec_kit_runtime-1.0.0.tar.gz
- Upload date:
- Size: 42.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a75ced4dfabf746afd57b2339fb27bd042c17a6114a9acb870c7372e68bec934
|
|
| MD5 |
eca8cacc3d287758dd6f575dde61a20e
|
|
| BLAKE2b-256 |
99ca97ac397dbcb85367f2ad2ee6e8e99a098cedff3ef224b44de09c5e40bba9
|
File details
Details for the file spec_kit_runtime-1.0.0-py3-none-any.whl.
File metadata
- Download URL: spec_kit_runtime-1.0.0-py3-none-any.whl
- Upload date:
- Size: 50.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1297bdbe343b20bea9c294be1c4cd90094f5c948f9a98de41f689fe1357baebf
|
|
| MD5 |
d2caf9c0c03dc4bf102b6ffab6739ebf
|
|
| BLAKE2b-256 |
d0caf064fdeae9c8ef711a54f4856ba2eb50ff4453b85c032af1e08cc7f9db9d
|