Skip to main content
VM creates and manages persistent CPU Linux machines with a durable root, systemd, optional Docker and SSH, a browser terminal, and an optional desktop. Choose Python or JavaScript below. Selecting a language switches every section on this page. JavaScript examples also work in TypeScript.

Installation and configuration

Install beam-client and provide a Beam token, or sign in with beam login.
Save this example as vm.py and run it with python vm.py:
The example leaves the VM paused. Save 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 22.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.

Find, connect and manage lifecycle

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.For an agent returning to a known workspace, use VM.connect(name_or_id). Creation rejects a name already in use. Reuse the same request_id UUID and identical configuration when retrying a 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 resource available for inspection and recovery.

Snapshots, forks and templates

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 pause() and resume().
Python snapshot and template creation returns artifact records. Launch from an artifact with VM(snapshot=ID) or VM(template=NAME_OR_ID). Omitted settings inherit the seed; 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:
See storage and snapshots for external mount boundaries and artifact retention after deleting a source VM.

Processes, stdin and logs

Process handles expose PID, 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. Detached jobs and background agents need an application-owned lease or idle stopping disabled.Run the installed coding-agent CLIs and inspect systemd logs through the process API:
Use 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:
Codex requires its working directory to be a Git repository. See Codex authentication and non-interactive mode.

Files, images, disks and Docker

vm.fs provides uploads/downloads, text and byte reads/writes, directories, metadata, search and replacement. Use vm.aio.fs for asynchronous operations.
Creation prepares registry images and Dockerfiles with the VM services. Images require Debian/Ubuntu with apt; desktop images require Ubuntu 22.04. Prebuilt image IDs must already contain those services. Use 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

Run an application on its guest port before requesting its URL. ports and protected_ports configure published URLs; expose() publishes another port. terminal_url and desktop_url are stable service URLs. Browser entry URLs exchange an expiring credential for an HTTP-only cookie. Rotating the traffic token revokes that token and the browser sessions. Network rules survive restart.For private TCP forwarding, SSH, SCP and local directory sync, use the CLI:
See networking and commands and SSH for access policies, SSH identity, recursive transfers and sync options.

Desktop controls

Create the VM with desktop=True to use the desktop APIs.
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 stop_recording(). Resolution supports 320–4096 by 200–2160; recording supports 1–60 FPS. See the desktop guide.

API reference

Use the VM lifecycle and port methods for the persistent resource. Its async process/filesystem/Docker interface reuses sandbox transports; sandbox termination and sandbox preview-URL methods are not replacements for VM lifecycle and stable URLs.