A TypeScript module that wraps Amazon's [Firecracker VMM](https://firecracker-microvm.github.io/) to create, configure, and manage lightweight microVMs with a clean, type-safe API.
## Issue Reporting and Security
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
## Install
```bash
pnpm install @push.rocks/smartvm
```
> ⚡ **Prerequisites**: Firecracker requires a Linux host with KVM support (`/dev/kvm`). Networking features (TAP devices, bridges, NAT) require root privileges.
{ifaceId:'eth0'},// TAP device and MAC auto-generated
],
});
// 4. Start it 🚀
awaitvm.start();
// 5. Inspect
console.log(vm.state);// 'running'
console.log(awaitvm.getInfo());// Firecracker instance info
// 6. Pause / Resume
awaitvm.pause();// state → 'paused'
awaitvm.resume();// state → 'running'
// 7. Stop and clean up
awaitvm.stop();
awaitvm.cleanup();
awaitsmartvm.cleanup();
```
## Architecture Overview
```
┌─────────────────────────────────────────────┐
│ SmartVM │ ← Top-level orchestrator
│ ┌──────────────┐ ┌────────────────────┐ │
│ │ ImageManager │ │ NetworkManager │ │
│ │ (binaries, │ │ (TAP, bridge, │ │
│ │ kernels, │ │ NAT, IP alloc) │ │
│ │ rootfs) │ │ │ │
│ └──────────────┘ └────────────────────┘ │
│ │
│ ┌─────────── MicroVM ────────────────┐ │
│ │ state: created → configuring → │ │
│ │ running → paused → stopped │ │
│ │ │ │
│ │ ┌──────────────────────────────┐ │ │
│ │ │ FirecrackerProcess │ │ │
│ │ │ (child process management) │ │ │
│ │ └──────────────────────────────┘ │ │
│ │ ┌──────────────────────────────┐ │ │
│ │ │ SocketClient │ │ │
│ │ │ (HTTP over Unix socket) │ │ │
│ │ └──────────────────────────────┘ │ │
│ │ ┌──────────────────────────────┐ │ │
│ │ │ VMConfig │ │ │
│ │ │ (camelCase → snake_case) │ │ │
│ │ └──────────────────────────────┘ │ │
│ └────────────────────────────────────┘ │
└─────────────────────────────────────────────┘
```
Firecracker exposes a REST API over a Unix domain socket. This module handles all the plumbing: spawning the process, waiting for the socket, translating your TypeScript config into Firecracker's snake_case API payloads, managing TAP devices, and tearing everything down on exit.
## API Reference
### `SmartVM` — The Orchestrator
The entry point for everything. Manages binary downloads, VM creation, and global cleanup.
Runtime files default to `/dev/shm/.smartvm/runtime` on Linux when available, so sockets and per-VM writable drive copies live on tmpfs and are removed during cleanup. Set `runtimeDir` to override this.
**Ephemeral drives:**
- Writable drives are copied into the per-VM runtime directory before boot by default
- Firecracker receives the staged tmpfs path, so guest writes do not modify cached/base rootfs files
- Per-VM staged drive files are deleted by `vm.cleanup()` / `smartvm.cleanup()`
- Read-only drives are not copied unless `ephemeral: true` is set on the drive
- Set `ephemeral: false` on a drive, or `ephemeralWritableDrives: false` on `SmartVM`, only when persistence is explicitly required
Downloads known base image bundles into a `/tmp` cache for integration tests and quick local smoke tests. The default preset is `latest`; `lts` maps to a pinned Firecracker CI train (`v1.7`) for a stable fallback. Hosted project-owned manifests are also supported for pinned Alpine/BusyBox-style bundles.
```typescript
constbaseImage=awaitsmartvm.ensureBaseImage();// same as { preset: 'latest' }
Hosted manifest format examples live in `assets/base-images/`. Hosted URL artifacts require SHA256 hashes; `smartvm` verifies them during download before returning the bundle paths.
- Deterministic MAC generation (`02:xx:xx:xx:xx:xx` locally-administered)
- TAP names fit Linux's 15-char IFNAMSIZ limit
### `VMConfig` — Config Transformer
Converts your camelCase TypeScript config into Firecracker's snake_case API payloads. Also validates configuration before boot.
```typescript
import{VMConfig}from'@push.rocks/smartvm';
constvmConfig=newVMConfig({
bootSource:{kernelImagePath:'/path/to/vmlinux'},
machineConfig:{vcpuCount: 2,memSizeMib: 256},
});
// Validate
constresult=vmConfig.validate();
// { valid: true, errors: [] }
// Generate API payloads
vmConfig.toBootSourcePayload();
// { kernel_image_path: '/path/to/vmlinux' }
vmConfig.toMachineConfigPayload();
// { vcpu_count: 2, mem_size_mib: 256 }
```
### `SocketClient` — Low-Level HTTP Client
Direct HTTP-over-Unix-socket communication with Firecracker. You typically don't need this directly — `MicroVM` handles it — but it's available if you want raw API access.
The default test suite is unit-level and safe to run without KVM or root privileges:
```bash
pnpm test
pnpm run build
```
These tests cover config validation, Firecracker payload generation, lifecycle guard errors, VM tracking, and subnet/IP allocation. They do not boot a real microVM.
Real Firecracker boot testing should be run on a Linux/KVM host with the runtime requirements above. At minimum, verify `ensureBinary()`, `createVM()`, `start()`, `getInfo()`, `stop()`, and `cleanup()` against a known-good kernel and rootfs image before relying on a new host setup.
An opt-in integration test scaffold is included and skipped by default:
```bash
SMARTVM_RUN_INTEGRATION=true pnpm test
```
Useful integration-test environment variables:
-`SMARTVM_BASE_IMAGE_PRESET`: `latest` or `lts` (default: `latest`)
-`SMARTVM_BASE_IMAGE_MANIFEST_URL`: use a hosted/project-owned base image manifest instead of a preset
-`SMARTVM_BASE_IMAGE_MANIFEST_PATH`: use a local base image manifest instead of a preset
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
### Company Information
Task Venture Capital GmbH
Registered at District Court Bremen HRB 35230 HB, Germany
For any legal inquiries or further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.