Skip to main content

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 contracts
  • pyyaml>=6.0 - Configuration parsing

License

MIT License - see LICENSE file for details.

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

spec_kit_runtime-1.0.0.tar.gz (42.9 kB view details)

Uploaded Source

Built Distribution

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

spec_kit_runtime-1.0.0-py3-none-any.whl (50.1 kB view details)

Uploaded Python 3

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

Hashes for spec_kit_runtime-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a75ced4dfabf746afd57b2339fb27bd042c17a6114a9acb870c7372e68bec934
MD5 eca8cacc3d287758dd6f575dde61a20e
BLAKE2b-256 99ca97ac397dbcb85367f2ad2ee6e8e99a098cedff3ef224b44de09c5e40bba9

See more details on using hashes here.

File details

Details for the file spec_kit_runtime-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for spec_kit_runtime-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1297bdbe343b20bea9c294be1c4cd90094f5c948f9a98de41f689fe1357baebf
MD5 d2caf9c0c03dc4bf102b6ffab6739ebf
BLAKE2b-256 d0caf064fdeae9c8ef711a54f4856ba2eb50ff4453b85c032af1e08cc7f9db9d

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