The TypeScript SDK is currently in beta. It’s an experimental SDK that allows
you to interact with Beam’s infrastructure and resources. Please contact us if
you have any feedback or questions.
Installation
Install the package withnpm
:
yarn
:
Configuration
Locate your Beam Token (API Key) and Workspace ID in the dashboard and set them as environment variables.beamOpts
Global configuration object for the Beam client.
token
: Your Beam authentication tokenworkspaceId
: Your Beam workspace ID
gatewayUrl
: The Beam gateway URL (defaults tohttps://app.beam.cloud
)
Quickstart
Run a simple Node.js server in a sandbox. This example uses theImage
class to create a custom container image and the Sandbox
class to create a sandbox instance.
Environment
Image
Defines a custom container image that your code will run in.
An Image object encapsulates the configuration of a custom container image that will be used as the runtime environment for executing tasks.
The Python version to be used in the image. Can be a PythonVersion enum (e.g.,
PythonVersion.Python311) or string literal (e.g., “python3.11”). Defaults to
Python 3.
A list of Python packages to install in the container image. Alternatively, a
string containing a path to a requirements.txt can be provided.
A list of shell commands to run when building your container image. These
commands can be used for setting up the environment, installing dependencies,
etc.
A custom base image to replace the default ubuntu20.04 image used in your
container. This can be a public or private image from Docker Hub, Amazon ECR,
Google Cloud Artifact Registry, or NVIDIA GPU Cloud Registry.
Credentials for accessing private registries. Can be a dictionary of key/value
pairs or an array of environment variable names.
Environment variables to add to the image. These will be available when
building the image and when the container is running.
A list of secrets that are injected into the container as environment
variables.
Builds the image on a GPU node. Can be a GpuType enum (e.g., GpuType.H100) or
string literal (e.g., “H100”).
Image.fromDockerfile()
Create an Image from a local Dockerfile.
Path to the Dockerfile.
Directory to sync as build context. Defaults to the Dockerfile directory.
Image.addPythonPackages()
Add pip packages to install during the build. Accepts a list or a path to requirements.txt.
Package names or a
requirements.txt
path.Image.withEnvs()
Add environment variables available during build and at runtime.
Environment variables as key/value pairs, array of “KEY=VALUE” strings, or
single string.
Image.withSecrets()
Expose platform secrets to the build environment.
Secret names created via the platform.
Image.micromamba()
Switch package management to micromamba and target a micromamba Python.
Image.addMicromambaPackages()
Install micromamba packages and optional channels.
Package names or a
requirements.txt
path.Micromamba channels.
Image.build()
Build the image and return the result.
Deployments
Deployments
You can use this to manage and interact with deployed Beam applications.
Deployments.list()
List all deployments in your workspace.
Deployments.get()
Retrieve a deployment by ID, name, or URL.
The deployment ID to retrieve.
The deployment name (must be used with stubType).
The stub type (must be used with name).
The deployment URL.
Deployment
A deployment instance with methods for interaction.
Deployment.call()
Call the deployment with data.
The data to send to the deployment.
Optional path to append to the deployment URL.
HTTP method to use for the request.
Deployment.realtime()
Connect to a realtime deployment via WebSocket.
Optional path to append to the WebSocket URL.
Optional message handler function.
Deployment.httpUrl()
/ Deployment.websocketUrl()
Get the HTTP or WebSocket URL for the deployment.
Sandbox
A sandboxed container for running Python code or arbitrary processes. You can use this to create isolated environments where you can execute code, manage files, and run processes.Sandbox.create()
Create a new sandbox instance.
Sandbox.connect()
Connect to an existing sandbox instance by ID.
The container ID of the existing sandbox instance.
Sandbox.createFromSnapshot()
Create a sandbox instance from a filesystem snapshot.
The ID of the snapshot to create the sandbox from.
SandboxInstance
A sandbox instance that provides access to the sandbox internals.SandboxInstance.runCode()
Run Python code in the sandbox.
The Python code to execute.
Whether to wait for the process to complete.
SandboxInstance.exec()
Run an arbitrary command in the sandbox.
The command and its arguments to execute.
SandboxInstance.exposePort()
Dynamically expose a port to the internet.
The port number to expose within the sandbox.
SandboxInstance.snapshot()
Create a filesystem snapshot of the current sandbox.
SandboxInstance.updateTtl()
Update the keep warm setting of the sandbox.
The number of seconds to keep the sandbox alive. Use -1 for sandboxes that
never timeout.
SandboxInstance.sandboxId()
Get the ID of the sandbox.
SandboxInstance.terminate()
Terminate the container associated with this sandbox instance.
SandboxProcess
Represents a running process within a sandbox.SandboxProcess.wait()
Wait for the process to complete.
SandboxProcess.kill()
Kill the process.
SandboxProcess.status()
Get the status of the process.
SandboxProcess.stdout
/ SandboxProcess.stderr
Get handles to the process output streams.
SandboxFileSystem
File system interface for managing files within a sandbox.SandboxFileSystem.uploadFile()
Upload a local file to the sandbox.
The path to the local file to upload.
The destination path within the sandbox.
SandboxFileSystem.downloadFile()
Download a file from the sandbox to a local path.
The path to the file within the sandbox.
The destination path on the local filesystem.
SandboxFileSystem.listFiles()
List the files in a directory in the sandbox.
The path to the directory within the sandbox.
SandboxFileSystem.deleteFile()
Delete a file in the sandbox.
The path to the file within the sandbox.
SandboxFileSystem.statFile()
Get metadata of a file in the sandbox.
The path to the file within the sandbox.
Pod
A Pod is an object that allows you to run arbitrary services in a fast, scalable, and secure remote container on Beam. You can think of a Pod as a lightweight compute environment that you fully control—complete with a custom container, ports you can expose, environment variables, volumes, secrets, and GPUs.Pod.create()
Create a new container that runs until it completes or is explicitly killed.
The command to run in the container.
Storage
Volume
Creates a Volume instance.
When your container runs, your volume will be available at ./{mountPath}
and /volumes/{name}
.
The name of the volume, a descriptive identifier for the data volume.
The path where the volume is mounted within the container environment.
Volume.getOrCreate()
Get or create the volume in the platform.
Utils
TaskPolicy
Task policy for managing the lifecycle of individual tasks.
The maximum number of times a task will be retried if the container crashes.
The maximum number of seconds a task can run before it times out. Set it to -1
to disable the timeout.
The expiration time for a task in seconds. Must be greater than 0 and less
than 24 hours (86400 seconds).
Types
The TypeScript SDK includes comprehensive type definitions for all resources:GpuType
: Enum of available GPU types (T4, A10G, A100, H100, etc.)GpuTypeAlias
: Union type allowing both enum values and string literals for GPU specificationPythonVersion
: Enum of supported Python versionsPythonVersionAlias
: Union type allowing both enum values and string literals for Python version specificationTaskStatus
: Enum of task statuses (PENDING, RUNNING, COMPLETE, etc.)DeploymentData
: Interface for deployment dataTaskData
: Interface for task dataPodInstanceData
: Interface for pod instance data- And many more…