Skip to content

SDK

Decorator SDK

Declare reproducible mvm workloads in Python or TypeScript and compile them into Workload IR without running untrusted code.

The decorator SDK is the build-time authoring surface. It lets a developer describe a workload next to the function or service it runs, then compile that declaration into the same Workload IR consumed by mvmctl machine build and mvmctl machine run.

This is the declarative side of the product: code-first workload declaration, resource selection, image selection, and deploy metadata. The security difference is intentional: the static compiler reads source and extracts literal declarations without importing the module.

For the full source-to-IR-to-build flow, see Declaration workflow. For concrete declaration patterns, see Declaration cookbook. For host execution, guest execution, and artifact boundary rules, see SDK security model.

import mvm
@mvm.app(
name="agent-tool",
source=mvm.local_path("."),
image=mvm.nix_packages(["python312", "uv"]),
resources=mvm.resources(cpu_cores=1, memory_mb=512, rootfs_size_mb=512),
network=mvm.network(
mode="none",
egress=mvm.egress([mvm.host_port("api.openai.com", 443)]),
),
env={
"OPENAI_API_KEY": mvm.secret("openai-api-key", type="bearer", hosts=["api.openai.com"]),
},
entrypoint=mvm.entrypoint_function(
module="tool",
function="run",
primary=True,
),
)
def run(prompt: str) -> str:
...

Compile and inspect:

Terminal window
mvmctl build compile tool.py --out /tmp/agent-tool
mvmctl machine build --flake /tmp/agent-tool
mvmctl machine run --flake /tmp/agent-tool

The safe path is static analysis: mvmctl build compile reads the declaration and emits IR without importing and executing the user’s source file. That keeps untrusted or side-effecting module import code out of the host process.

Record-mode and live-mode runtime scripts exist for the imperative Sandbox.create(...) workflow, but they have a different trust posture because the user’s script runs on the host process invoking the SDK. Prefer the static declaration form for security-sensitive deployable workloads.

FieldPurposeSecurity notes
sourceFiles to package.Should avoid broad host directories such as $HOME.
imageNix package set or OCI source.Nix is preferred; OCI refs should be immutable for production.
resourcesCPU, memory, rootfs sizing.Bounds prevent accidental host pressure.
networkEgress and port policy.Default should be deny unless explicitly opened.
envLiteral values and secret references.Use mvm.secret, not plaintext credentials.
entrypointFunction or command dispatch.Dispatch runs in the guest microVM.
hooksBuild/start/readiness/stop hooks.Hooks must not bypass policy or fetch unpinned code.

The decorator SDK declares what to build and run. The runtime SDK owns a sandbox lifecycle from application code. They can be combined: a decorator declaration can produce a reproducible artifact, and a runtime SDK client can launch that artifact under explicit policy.