VM creates and manages persistent CPU Linux machines with a durable root,
systemd, optional Docker and SSH, a browser terminal, and an optional desktop.
Select Python or JavaScript to switch all examples on this page. JavaScript
examples also work in TypeScript; the package includes declarations.
New VMs protect terminal 7681 and enabled desktop 8080 by default. Use authenticated entry URLs as described in networking.
Installation and configuration
- Python
- JavaScript
Install Save this example as The example leaves the VM paused. Save
beam-client and provide a Beam token, or sign in with beam login.vm.py and run it with python vm.py:vm.id and use VM.connect(id) for the
next session; vm.remove() deletes it. Closing the client or exiting a with
block does not stop or delete the VM.The default image is Ubuntu 24.04, with 4 CPU cores, 8192 MiB of RAM and a
50 GiB writable root. Python uses CPU cores and memory in MiB. Use
context="PROFILE" to select a named CLI profile, or pass a ConfigContext
for explicit credentials and gateway settings. VMs are CPU-only.desktop=True in Python or desktop: true in JavaScript; it requires at least 1024 MiB RAM. Enable Docker with docker_enabled=True or dockerEnabled: true, respectively.
Find, connect and manage lifecycle
- Python
- JavaScript
VM.list() returns management records. create(), start(), connect() and
fork() wait for exec readiness by default; use create(wait=False) or
start(wait=False) to submit, then call wait(). Python wait deadlines are in
seconds. get() and list() do not wake sleeping VMs. Guest operations can
wake a VM when auto_resume is enabled.ttl measures idle seconds. It stops or pauses the VM instead of deleting it.
stop(no_snapshot=True) skips the visible stop snapshot while retaining the
durable root. pause() saves RAM and the paired disk state.Reconnect to an existing VM with VM.connect(name_or_id). Creation rejects a
name already in use. Reuse the same request_id UUID and identical configuration
when retrying creation across application restarts. Repeated create() calls
on the same prepared object retain the image, keys and request. prepare()
resolves them without starting compute. A readiness timeout leaves the VM
available for inspection and recovery.Snapshots, forks and templates
- Python
- JavaScript
Snapshots and templates are immutable disk artifacts. They outlive their
source VM and capture the root, not RAM or external shared volumes. Preserve
running processes with Python snapshot and template creation returns artifact records. Launch from
an artifact with See storage and snapshots for external mount boundaries and
artifact retention after deleting a source VM.
pause() and resume().VM(snapshot=ID) or VM(template=NAME_OR_ID). Omitted settings
inherit the snapshot or template configuration; explicit settings override it.
Templates are private. Restore
creates a new VM; there is no in-place rollback.Use the CLI for workspace-wide artifact listing and template management:Processes, stdin and logs
- Python
- JavaScript
wait, kill, stdout/stderr streams and iterable
logs. Arguments are literal; use sh -lc when you need shell syntax. Stdin
accepts text, bytes or a binary file. A wait timeout ends the wait without
killing the command. Handles belong to their original runtime; resolve new
handles after a restart. The async process, filesystem and Docker interfaces
are available through vm.aio.Hold vm.keep_alive() around long work on an idle-limited VM, including detached
jobs and background agents. Alternatively, disable idle stopping.Run the installed coding-agent CLIs and inspect systemd logs through the
process API:beam vm prompt and beam vm logs for managed background sessions and
session/unit/PID log following. Supply agent credentials using VM environment
variables or workspace secrets. For headless Codex, provide CODEX_API_KEY,
or authenticate its guest CLI with an injected OPENAI_API_KEY before execution:Files, images, disks and Docker
Runtimesecrets require approved hosts. The VM receives placeholders instead of secret values. Create API_KEY with host rules before using these examples; see VM secrets for creation, guest requests, rotation, and client compatibility. Python process calls inherit the VM’s secret bindings; MCP vm_exec.secrets can add bindings for an individual command.
- Python
- JavaScript
vm.fs provides uploads/downloads, text and byte reads/writes, directories,
metadata, search and replacement. Use vm.aio.fs for asynchronous operations.prepare() to
build and resolve a launch request without starting compute, or
beam vm image build for a standalone VM image build.Additional named disks and workspace volumes persist independently of the VM.
Snapshot/template launches inherit the image and root; omit image there.
Docker calls return result handles; call wait() and read their stdout and
stderr properties. Compose helpers and async Docker calls are documented in
Docker and Compose.URLs, protected ports and private access
- Python
- JavaScript
ports and
protected_ports configure published URLs; public_ports opts out of system-port defaults at creation. expose() publishes an application port or toggles terminal/desktop protection.
terminal_url and desktop_url are stable service URLs; protected URLs require
access_url() for browsers or the traffic token header for HTTP clients.
Browser entry URLs exchange an expiring credential for a Secure, HTTP-only,
host-scoped cookie. Anyone holding the link can access that port until expiry.
Rotating the traffic token revokes that token and the browser sessions.
Network rules survive restart. vm.public_ipv6 reads the persistent IPv6
address from resolved metadata without another request, or returns None
when no address has been allocated; see direct IPv6 access.For private TCP forwarding, SSH, SCP and local directory sync, use the CLI:Desktop controls
- Python
- JavaScript
Create the VM with Screenshots return PNG bytes and can save to a local path. Text uses the
clipboard for literal UTF-8. Recordings use guest CPU encoding and are
finalized by
desktop=True to use the desktop APIs.stop_recording(). Resolution supports 320–4096 by 200–2160;
recording supports 1–60 FPS. See the desktop guide.API reference
- Python
- JavaScript
Use
VM methods to manage lifecycle and ports. The async process/filesystem/Docker interface shares sandbox transports, but sandbox termination and sandbox preview-URL methods cannot manage VM lifecycle or stable URLs.