monocore is the engine behind the monocore platform, providing a robust foundation for running AI workloads in isolated microVMs. It handles everything from VM lifecycle management to OCI image distribution, making it easy to deploy and orchestrate code sandboxes securely.
[!WARNING] This project is in early development and is not yet ready for production use.
Table of Contents
Overview
When developing AI agents that execute code, you need a fast development cycle:
- Docker containers? Limited isolation for untrusted code
- Traditional VMs? Minutes to start up, heavy resource usage
- Direct execution? Risky for your development machine
- Cloud sandboxes? Great for production, but slow for rapid iteration
monocore provides:
- 🔒 True VM-level isolation
- ⚡ Millisecond startup times
- 🎯 Simple REST API
- 📦 Works with standard container images
- 🔧 Full resource control
- 💻 Perfect for local development
Library Usage
Basic MicroVM
use MicroVm;
async
Service Orchestration
use ;
async
Getting Started
Installation
Quick Install:
|
This will install both the monocore command and its alias mc.
System Requirements:
- KVM-enabled Linux kernel (check with
ls /dev/kvm) - User must be in the
kvmgroup (add withsudo usermod -aG kvm $USER)
- Apple Silicon (ARM64) only
- macOS 10.15 (Catalina) or later for Hypervisor.framework support
Coming soon!
Manual Build:
# Clone the repository
# Build and install (installs to /usr/local/bin)
&&
Basic Usage
- Create a configuration file:
# monocore.toml
[[]]
= "sh-counter"
= "alpine:latest"
= 256
= 1
= "demo"
= "/bin/sh"
= ["-c", "for i in $(seq 1 10); do echo $i; sleep 2; done"]
[[]]
= "python-counter"
= "python:3.11-slim"
= 256
= 1
= "demo"
= "/usr/local/bin/python3"
= [
"-c",
"import time; count=0; [print(f'Count: {count+1}') or time.sleep(2) or (count:=count+1) for _ in range(10)]",
]
[[]]
= "demo"
= true
- Manage your services:
# Start services
# View status
# Stop services
# Remove services
- Run in server mode:
# Start the REST API server (default port: 3456)
# Or use the default port
For more CLI options:
Configuration Schema
The monocore.toml configuration file supports the following structure:
# Service Definition
[[]]
= "service-name" # Required: Name of the service
= "image:tag" # Optional: Base OCI image to use
= "group-name" # Optional: Group this service belongs to
= "/path/to/binary" # Optional: Command to run
= ["arg1", "arg2"] # Optional: Arguments for the command
= 1 # Optional: Number of vCPUs (default: 1)
= 1024 # Optional: RAM in MiB (default: 1024)
= "/app" # Optional: Working directory
= "8080:80" # Optional: Port mapping (host:guest)
= ["/host:/guest"] # Optional: Volume mappings
= ["KEY=value"] # Optional: Environment variables
= ["other-service"] # Optional: Service dependencies
= ["prod"] # Optional: Environment variables for the group
= [ # Optional: Volume mappings for the group
{
name = "shared-data", # Required: Name of the volume
path = "/data:/data" # Required: Path mapping (host:guest)
}
]
# Group Definition
[[]]
= "group-name" # Required: Name of the group
= true # Optional: Restrict connection to local network (default: true)
# Group volume definition
[[]]
= "shared-data" # Required: Name of the volume
= "/data" # Required: Base path on host system
# Group environment variables
[[]]
= "prod" # Required: Name of the environment group
= ["API_KEY=value"] # Optional: Environment variables
Volume Mappings
Volumes can be specified in two formats:
- Single path (
/data): Uses the same path on both host and guest - Path pair (
/host:/guest): Maps host path to a different guest path
Port Mappings
Ports can be specified in two formats:
- Single port (
8080): Uses the same port on both host and guest - Port pair (
8080:80): Maps host port to a different guest port
Service Groups
Services can be organized into groups for:
- Shared volume definitions
- Common environment variables
- Network isolation (when
local_only = true) - Resource management
Dependencies
- Services can specify dependencies using
depends_on - Maximum dependency chain length is 32
- Services are started in dependency order
REST API
When running in server mode, monocore provides a REST API for managing services:
| Endpoint | Method | Description |
|---|---|---|
/up |
POST | Start services defined in config |
/down |
POST | Stop running services |
/status |
GET | Get status of all services |
/remove |
POST | Remove service files |
Example API usage:
# Start services
# Get service status
# Stop services in a group
# Remove services
Features
Secure Isolation
- Isolated microVM environments for each service
- Resource constraints and limits enforcement
- Network isolation between service groups
- Perfect for running untrusted AI-generated code
- Full system call isolation
Efficient Runtime
- Fast microVM provisioning and startup
- Millisecond-level boot times
- Minimal resource overhead
- Optimized layer caching and sharing
- Memory-efficient design
OCI Integration
- Pull images from any OCI-compliant registry
- Smart layer management and deduplication
- Local image caching for faster startups
- Support for standard container images
- Seamless Docker compatibility
Service Orchestration
- Dependency-aware service scheduling
- Health monitoring and automatic recovery
- Log rotation with configurable retention
- Resource usage tracking
- Group-based service management
Architecture
Directory Structure
Monocore maintains its state in ~/.monocore:
graph TD
monocore_root[~/.monocore] --> monoimage[monoimage/]
monoimage --> monoimage_repo[repo/]
monoimage_repo --> monoimage_cid["[repo-name]__[tag].cid"]
monoimage --> monoimage_layer[layer/]
monocore_root --> oci[oci/]
oci --> oci_repo[repo/]
oci_repo --> oci_tag["[repo-name]__[tag]/"]
oci_tag --> oci_config[config.json]
oci_tag --> oci_manifest[manifest.json]
oci_tag --> oci_index[index.json]
oci --> oci_layer[layer/]
oci_layer --> oci_layer_hash["[hash]"]
monocore_root --> rootfs[rootfs/]
rootfs --> rootfs_service[service/]
rootfs_service --> rootfs_service_rootfs["[service-name]/"]
rootfs --> rootfs_ref[reference/]
rootfs_ref --> rootfs_ref_repo["[repo-name]__[tag]/"]
rootfs_ref_repo --> rootfs_ref_repo_merged[merged/]
monocore_root --> service[service/]
service --> service_info["[service-name]/"]
service_info --> service_json[service.json]
service_info --> group_json[group.json]
monocore_root --> run[run/]
run --> run_service["[service-name]__[pid].json"]
monocore_root --> log[log/]
log --> log_stderr["[service-name].stderr.log"]
log --> log_stdout["[service-name].stdout.log"]
Development
For development setup and building from source, please visit the root of the project repository.
License
This project is licensed under the Apache License 2.0.