Windows Sandboxes
Modal Sandboxes can run Windows Server 2025. Pass a Windows Image to Sandbox.create() and standard Sandbox APIs (exec(), modal shell, Sandbox.filesystem, Volumes, Cloud Bucket Mounts, Secrets, snapshots, Tunnels, Connect Tokens,
and outbound allowlists)
work out of the box.
Getting started
Start from Modal’s Windows Server 2025 Named Image (modal/base/windows-server:latest, or a date-pinned tag like modal/base/windows-server:2026-12-03 for reproducible builds):
import modal
app = modal.App.lookup("windows-sandbox", create_if_missing=True)
image = modal.Image.from_name("modal/base/windows-server:latest")
sb = modal.Sandbox.create(app=app, image=image, cpu=4, memory=8192)
try:
p = sb.exec("cmd", "/c", "ver && whoami")
print(p.stdout.read())
finally:
sb.terminate()import { ModalClient } from "modal";
const modal = new ModalClient();
const app = await modal.apps.fromName("windows-sandbox", {
createIfMissing: true,
});
const image = await modal.images.fromName("modal/base/windows-server:latest");
const sb = await modal.sandboxes.create(app, image, {
cpu: 4,
memoryMiB: 8192,
});
try {
const p = await sb.exec(["cmd", "/c", "ver && whoami"]);
console.log(await p.stdout.readText());
} finally {
await sb.terminate();
}package main
import (
"context"
"fmt"
"io"
modal "github.com/modal-labs/modal-client/go"
)
func main() {
ctx := context.Background()
mc, err := modal.NewClient()
if err != nil {
panic(err)
}
app, err := mc.Apps.FromName(ctx, "windows-sandbox", &modal.AppFromNameParams{
CreateIfMissing: true,
})
if err != nil {
panic(err)
}
image, err := mc.Images.FromName(ctx, "modal/base/windows-server:latest", nil)
if err != nil {
panic(err)
}
sb, err := mc.Sandboxes.Create(ctx, app, image, &modal.SandboxCreateParams{
CPU: 4,
MemoryMiB: 8192,
})
if err != nil {
panic(err)
}
defer sb.Terminate(ctx, nil)
p, err := sb.Exec(ctx, []string{"cmd", "/c", "ver && whoami"}, nil)
if err != nil {
panic(err)
}
stdout, err := io.ReadAll(p.Stdout)
if err != nil {
panic(err)
}
fmt.Println(string(stdout))
}Customizing the Image
Customize the base Image by booting a Sandbox, installing packages via exec(),
and saving a Filesystem Snapshot as a Named Image.
Filesystem Snapshots expire after 30 days by default. Disable expiry when building a long-lived Image (see Snapshot Retention):
import modal
app = modal.App.lookup("windows-image-build", create_if_missing=True)
base = modal.Image.from_name("modal/base/windows-server:2026-12-03")
sb = modal.Sandbox.create(app=app, image=base, cpu=4, memory=8192)
try:
p = sb.exec(
"powershell",
"-NoProfile",
"-Command",
"$ErrorActionPreference = 'Stop'; "
"Invoke-WebRequest -UseBasicParsing https://example.com/app.msi -OutFile C:\\app.msi; "
"$p = Start-Process msiexec.exe -Wait -PassThru -ArgumentList '/i C:\\app.msi /qn /norestart'; "
"if ($p.ExitCode -ne 0) { exit $p.ExitCode }",
)
if (code := p.wait()) != 0:
raise RuntimeError(f"installer failed with exit code {code}")
sb.snapshot_filesystem(ttl=None).publish("my-windows-env:v1")
finally:
sb.terminate()
# Launch later from your published Image
sb2 = modal.Sandbox.create(
app=app,
image=modal.Image.from_name("my-windows-env:v1"),
cpu=4,
memory=8192,
)
try:
...
finally:
sb2.terminate()import { ModalClient } from "modal";
const modal = new ModalClient();
const app = await modal.apps.fromName("windows-image-build", {
createIfMissing: true,
});
const base = await modal.images.fromName(
"modal/base/windows-server:2026-12-03",
);
const sb = await modal.sandboxes.create(app, base, {
cpu: 4,
memoryMiB: 8192,
});
try {
const p = await sb.exec([
"powershell",
"-NoProfile",
"-Command",
"$ErrorActionPreference = 'Stop'; " +
"Invoke-WebRequest -UseBasicParsing https://example.com/app.msi -OutFile C:\\app.msi; " +
"$p = Start-Process msiexec.exe -Wait -PassThru -ArgumentList '/i C:\\app.msi /qn /norestart'; " +
"if ($p.ExitCode -ne 0) { exit $p.ExitCode }",
]);
const code = await p.wait();
if (code !== 0) {
throw new Error(`installer failed with exit code ${code}`);
}
const custom = await sb.snapshotFilesystem({ ttlMs: null });
await custom.publish("my-windows-env:v1");
} finally {
await sb.terminate();
}
// Launch later from your published Image
const customImage = await modal.images.fromName("my-windows-env:v1");
const sb2 = await modal.sandboxes.create(app, customImage, {
cpu: 4,
memoryMiB: 8192,
});
try {
// ...
} finally {
await sb2.terminate();
}package main
import (
"context"
"fmt"
modal "github.com/modal-labs/modal-client/go"
)
func main() {
ctx := context.Background()
mc, err := modal.NewClient()
if err != nil {
panic(err)
}
app, err := mc.Apps.FromName(ctx, "windows-image-build", &modal.AppFromNameParams{
CreateIfMissing: true,
})
if err != nil {
panic(err)
}
base, err := mc.Images.FromName(ctx, "modal/base/windows-server:2026-12-03", nil)
if err != nil {
panic(err)
}
sb, err := mc.Sandboxes.Create(ctx, app, base, &modal.SandboxCreateParams{
CPU: 4,
MemoryMiB: 8192,
})
if err != nil {
panic(err)
}
defer sb.Terminate(ctx, nil)
p, err := sb.Exec(ctx, []string{
"powershell",
"-NoProfile",
"-Command",
`$ErrorActionPreference = 'Stop'; Invoke-WebRequest -UseBasicParsing https://example.com/app.msi -OutFile C:\app.msi; $p = Start-Process msiexec.exe -Wait -PassThru -ArgumentList '/i C:\app.msi /qn /norestart'; if ($p.ExitCode -ne 0) { exit $p.ExitCode }`,
}, nil)
if err != nil {
panic(err)
}
exitCode, err := p.Wait(ctx, nil)
if err != nil || exitCode != 0 {
panic(fmt.Sprintf("installer failed (code=%d, err=%v)", exitCode, err))
}
custom, err := sb.SnapshotFilesystem(ctx, &modal.SandboxSnapshotFilesystemParams{
TTL: modal.NoExpiryTTL,
})
if err != nil {
panic(err)
}
if err := custom.Publish(ctx, "my-windows-env:v1", nil); err != nil {
panic(err)
}
// Launch later from your published Image
customImage, err := mc.Images.FromName(ctx, "my-windows-env:v1", nil)
if err != nil {
panic(err)
}
sb2, err := mc.Sandboxes.Create(ctx, app, customImage, &modal.SandboxCreateParams{
CPU: 4,
MemoryMiB: 8192,
})
if err != nil {
panic(err)
}
defer sb2.Terminate(ctx, nil)
}Desktop and computer use
Windows Sandboxes include a 1920x1080 desktop display, so GUI apps,
screenshots (Pillow, mss, pyautogui), and mouse/keyboard input
(pyautogui, pywinauto, Windows UI Automation) work directly from exec().
Fast rollouts with Memory Snapshots
For fast startup in evals or computer-use loops, take a Memory Snapshot of a booted Sandbox and restore from it.
Wait for all exec() calls to finish before taking a Memory Snapshot, and start
any GUI app or background service you want open in the snapshot from the Sandbox
entrypoint or a Windows scheduled task (processes started by exec() stop when
that exec() exits; see Memory Snapshot limitations).
Viewing the desktop live
Install a VNC server (such as TightVNC + noVNC) and expose it over encrypted_ports with Connect Tokens for authenticated browser access, or over unencrypted_ports for raw VNC
(5900). See Watch a computer-use agent work in real-time over VNC for the general VNC-over-tunnel pattern on Modal.
Resources and pricing
- CPU:
0.125vCPUs minimum and default; CPU bursting works the same as on Linux Sandboxes. - Memory:
2048MiB minimum and default. Memory bursting is not supported yet, so sizememoryfor peak usage. - Disk:
512GiB.
Windows Sandbox pricing:
| Resource | Per second | Per hour |
|---|---|---|
| CPU | $0.00005913 / vCPU / s | $0.2129 / vCPU / hr |
| Memory | $0.00000667 / GiB / s | $0.0240 / GiB / hr |
See Sandbox pricing and resources for general billing details.
Limitations
- Directory Snapshots:
snapshot_directory()andmount_image()are not supported. - Sidecars: Sandbox Sidecars are not supported.
- Secret injection and HTTPS inspection: Secret injection and HTTPS-decrypting Outbound Policies are not supported. IP/CIDR and domain allowlists work.
block_network=True: Useoutbound_policy=modal.OutboundPolicy(routes=[modal.OutboundRoute.any().block()])to block outbound traffic instead.- Drive-letter paths in SDKs: Pass
/...paths (rooted onC:\, e.g./Users/Administrator/app) toworkdir,volumes,cloud_bucket_mounts, andSandbox.filesysteminstead ofC:\.... - GPUs and ARM64: Windows Sandboxes run on
x86_64CPUs only. - Sandboxes only: Modal Functions, Classes, and Endpoints are not supported.