.NET examples

August 3, 2026 ยท View on GitHub

These standalone SDK examples are .NET 10 file-based apps. Each source file references the local SDK through a #:project directive.

ExampleDemonstrates
basic.csCreate, exec, shell, filesystem, metrics, stop, and remove
streaming-exec.csTyped stdout/stderr events, exit status, and signals
filesystem.csGuest file operations, host transfer, and streaming I/O
detached.csDetach, list, reconnect, verify persistence, and clean up
metrics.csPoint, streaming, and all-sandbox metrics
snapshot-fork.csSnapshot creation, verification, indexing, and forking
ports.csTCP host-to-guest port publishing
volumes.csNamed volume creation, listing, duplicate errors, and removal
secrets.csSecret placeholders without guest-value exposure
patches.csRoot filesystem text, append, mkdir, symlink, copy, and remove patches

Run

Install the .NET 10 SDK, or install it with mise. Confirm that the SDK is available:

dotnet --version

Quick start with release binaries

From the repository root, download the latest release, verify its checksums, and load the generated environment file. The version property compiles the checkout's managed SDK against that exact native release:

dotnet run --file scripts/download-runtime.cs
source .runtime/env.sh
dotnet run --file examples/basic.cs -p:Version="$MICROSANDBOX_RELEASE_VERSION"

PowerShell uses the same downloader:

dotnet run --file scripts/download-runtime.cs
. .\.runtime\env.ps1
dotnet run --file examples/basic.cs -p:Version=$env:MICROSANDBOX_RELEASE_VERSION

This downloads msb, libkrunfw, and the native FFI library into the ignored .runtime directory. It does not require Rust, Go, Docker, just, or a native build toolchain.

Run any example directly with the .NET CLI:

dotnet run --file examples/basic.cs -p:Version="$MICROSANDBOX_RELEASE_VERSION"
dotnet run --file examples/streaming-exec.cs -p:Version="$MICROSANDBOX_RELEASE_VERSION"
dotnet run --file examples/filesystem.cs -p:Version="$MICROSANDBOX_RELEASE_VERSION"
dotnet run --file examples/detached.cs -p:Version="$MICROSANDBOX_RELEASE_VERSION"
dotnet run --file examples/metrics.cs -p:Version="$MICROSANDBOX_RELEASE_VERSION"
dotnet run --file examples/snapshot-fork.cs -p:Version="$MICROSANDBOX_RELEASE_VERSION"
dotnet run --file examples/ports.cs -p:Version="$MICROSANDBOX_RELEASE_VERSION"
dotnet run --file examples/volumes.cs -p:Version="$MICROSANDBOX_RELEASE_VERSION"
dotnet run --file examples/secrets.cs -p:Version="$MICROSANDBOX_RELEASE_VERSION"
dotnet run --file examples/patches.cs -p:Version="$MICROSANDBOX_RELEASE_VERSION"

Use the packaged FFI runtime

This repository does not build native code from source. mise run native-download downloads and checksum-validates the five upstream release binaries. NuGet consumers resolve their RID asset automatically; source-checkout examples can point at a staged current-platform binary. MICROSANDBOX_MSB_PATH is optional when msb is discoverable:

mise run native-download
export MICROSANDBOX_FFI_LIBRARY="$PWD/src/Microsandbox/runtimes/osx-arm64/native/libmicrosandbox_go_ffi.dylib" # macOS arm64

dotnet run --file examples/basic.cs

On Linux, use the staged linux-x64 or linux-arm64 .so. The prebuilt assets come from superradcompany/microsandbox releases and are not committed here.

Build every example without running a VM:

for example in examples/*.cs; do dotnet build "$example"; done