Concise contributor guide for working in this repo.
Matchlock is a Go-based micro-VM sandbox for running AI-generated code with:
- cross-platform VM backends (Linux + macOS/Apple Silicon)
- network interception/policy controls
- secret protection
- host-guest communication over vsock
- JSON-RPC control surface
- Go 1.25
- Linux VM backend: Firecracker (
pkg/vm/linux) - macOS VM backend: Virtualization.framework (
pkg/vm/darwin) - Network:
- Linux: nftables transparent proxy + HTTP/TLS MITM
- macOS: native NAT or gVisor userspace stack when interception is required
- VFS: pluggable providers in
pkg/vfs
cmd/matchlock: CLIcmd/guest-init: unified in-VM runtime entrypoint (init/agent/fused dispatch)internal/guestruntime/agent: in-VM exec agent runtimeinternal/guestruntime/fused: in-VM FUSE daemon runtimepkg/sandbox: sandbox lifecycle + exec relaypkg/image: image pull/import/build + rootfs preppkg/net: interception, MITM, policy plumbingpkg/rpc: JSON-RPC serverpkg/policy: allowlist + secret replacementpkg/state: VM/subnet state on hostinternal/errx: sentinel error wrapping helpers
Always build with mise, not raw go build.
# one-time local tooling install
mise install# macOS (usable, codesigned binary for usage and acceptance tests)
mise run build
# Linux (usable binary + one-time setup)
mise run build && sudo ./bin/matchlock setup linuxLinux sudo rule:
- Use
sudoonly for the one-timesetup linux/setup usercommands above. - Do not run
matchlock runormatchlock execwithsudo. - NEVER EVER run
matchlockwithsudo.
- Linux package artifacts are generated with GoReleaser/nfpm via
mise run package:linux. - Use
mise run package:linux:snapshotfor local snapshot/test artifacts. - Starter package config lives in
.goreleaser.yamlandpackaging/linux/. - Package lifecycle scripts must stay machine-safe: capabilities/sysctl/module loading are okay; user-specific
usermodlogic is not.
mise run test
mise run test:acceptance
mise run test:coverage
mise run check
mise run check:errx
mise run fmt
mise run package:linux
mise run package:linux:snapshotTesting standard:
- Use
testify/requireandtestify/assert. - Use
requirefor hard preconditions;assertfor follow-on checks.
Use sentinel errors per package (errors.go) and wrap with internal/errx.
- Define sentinels with
errors.New. - Wrap underlying errors with
errx.Wrap. - Add context with
errx.With. - Use
errors.Isat call sites. - Avoid direct
%wfmt.Errorfin packages (enforced bymise run check:errx).
Example pattern:
var ErrParseReference = errors.New("parse image reference")
if err != nil {
return errx.Wrap(ErrParseReference, err)
}- Keep host-side behavior cross-platform unless platform-specific behavior is required.
- Preserve parity between Linux/macOS guest-agent exec semantics where feasible.
- Keep cancellation semantics intact (host cancel -> guest process termination).
5000: exec service (host -> guest)5001: VFS service (guest -> host)5002: ready signal (host -> guest)
- Host-initiated calls use
CONNECT <port>on basevsock.sock. - Guest-initiated calls use
{uds_path}_{port}listener sockets. - Do not mix the two patterns.
- Default: native NAT (no interception).
- Interception mode activates when policy/secret features require it (for example
--allow-host,--secret).
createexecexec_streamwrite_fileread_filelist_filesallow_list_addallow_list_deleteport_forwardcancelclose
cancel should reliably stop in-flight execution via context cancellation and connection teardown.
- Kernel version is pinned in
pkg/kernel/kernel.goand distributed via GHCR. - Guest kernel configs live under
guest/kernel/. - Image cache/local store lives under
~/.cache/matchlock/images/.
matchlock run --image alpine:latest cat /etc/os-release
matchlock run --image alpine:latest -it sh
matchlock run --image alpine:latest --rm=false
matchlock exec <vm-id> echo hello
matchlock list
matchlock kill <vm-id>
matchlock prune
matchlock rpc- macOS backend supports Apple Silicon only (not Intel).
- gVisor userspace stack is used on macOS interception path; Linux uses nftables.
- Some subsystems still need deeper tests (see package tests and acceptance coverage).