Skip to content

Run Docker containers inside Vercel Sandbox

1 min read

Vercel Sandbox now supports installing and running Docker inside a sandbox. An agent can build containers, install system packages, and modify files without touching your host system.

Install Docker, start the daemon, and serve a containerized application:

import { Sandbox } from "@vercel/sandbox";
const sandbox = await Sandbox.create();
await sandbox.runCommand({
sudo: true,
cmd: "dnf",
args: ["install", "-y", "docker"]
});
// Start docker daemon and wait for it to be ready
await sandbox.runCommand({ sudo: true, cmd: "dockerd", detached: true });
await sandbox.runCommand({
cmd: "sh",
args: [ "-lc", "until sudo docker info >/dev/null 2>&1; do sleep 1; done"]
});
await sandbox.runCommand({
cmd: "docker",
args: [
"run", "--rm", "-d",
"--name", "redis",
"redis:alpine"
]
});
await sandbox.runCommand({
cmd: "docker",
args: ["exec", "redis", "redis-cli", "PING" ]
});

Docker in a Sandbox is useful for running containerized services like Redis or Postgres as test dependencies, validating container images before deploying, or previewing applications served from a container. Combined with persistent sandboxes, the Docker installation and pulled images carry over between sessions.

As well as adding support for Docker, sandboxes now support FUSE filesystem drivers and VPN clients, unlocking unlimited capabilities to what can be built.

Learn more about these new system specifications in the documentation.