Compute
Run containers, agents, and inference workloads on managed or self-hosted infrastructure.
Chalk Compute is a container runtime for running arbitrary workloads — AI agents, model inference, data pipelines, or any long-running process — in isolated, sandboxed environments. Workloads can run on Chalk’s managed serverless fleet or on your own EKS/GKE clusters.
To use Compute on a cluster, follow the Compute Setup guide.
Then install the SDK to get started:
pip install chalkcomputeEvery workload runs in a gVisor-isolated sandbox with its own filesystem, network namespace, and resource limits. Sandboxes support CPU and GPU workloads, enforce multi-tenant isolation at the kernel level, and can be deployed on managed infrastructure or self-hosted Kubernetes.
from chalkcompute import Container, Image
c = Container(image=Image.debian_slim(), cpu="2", memory="4Gi").run()
result = c.exec("python", "-c", "print('hello from a sandbox')")
print(result.stdout_text)
c.stop()Images define the software environment for a sandbox. The Image
API provides a fluent builder for installing pip packages, system dependencies, and local
files. Images are content-addressed — identical specs share a cached build, and incremental
changes only rebuild affected layers.
img = (
Image.debian_slim("3.12")
.pip_install(["torch", "transformers"])
.run_commands(
"apt-get update",
"apt-get install -y ffmpeg",
)
)Volumes provide persistent, versioned file storage backed by object storage. A Rust-based FUSE driver mounts volumes directly into containers as normal directories. Writes use batch copy-on-write semantics — changes are buffered locally and flushed on sync, giving other consumers a consistent view. Past versions are retained, enabling fork semantics for parallel agent workloads.
from chalkcompute import Container, Image, Volume
vol = Volume("training-data")
vol.put_file("inputs/example.txt", b"hello from a volume\n")
c = (
Container(image=Image.debian_slim("3.12"), name="volume-demo")
.mount_volume("training-data", "/data")
.run()
)
result = c.exec("python3", "-c", "print(open('/data/inputs/example.txt').read())")
print(result.stdout_text)
c.stop()
Functions let you deploy a Python callable as a remotely invocable endpoint. Chalk handles image building, scaling, and routing — you write a function, deploy it, and call it from anywhere.
import chalkcompute
@chalkcompute.function(cpu="1", memory="1Gi")
def normalize_name(name: str) -> str:
return " ".join(part.capitalize() for part in name.split())
normalize_name.wait_ready()
print(normalize_name("ada lovelace")) # Ada LovelaceThe Function Queue provides durable, ordered task execution for functions. Enqueue work items and let Chalk manage retries, concurrency limits, and backpressure.
import chalkcompute
@chalkcompute.function(concurrency=4, retries=3)
async def stream_words(text: str):
for word in text.split():
yield word
stream_words.wait_ready()
for word in stream_words("hello from the queue"):
print(word)Inject secrets into sandboxes, containers, and functions via the Secret API.
Secrets are resolved at deploy time and exposed to the workload as environment
variables. The four factory constructors cover the common cases:
Secret.from_env(name) —
read from Chalk’s managed secret store by name.Secret.from_integration(name) —
expose the credentials of a named Chalk integration (e.g. "prod_postgres")
as standard env vars.Secret.from_local_env(name, env_var_name=...) —
forward a secret from the local environment at deploy time (handy for dev
loops).Secret.from_local_env_file(path) —
forward every entry in a local .env file.import os
from urllib.parse import urlparse
import chalkcompute
from chalkcompute import Secret
@chalkcompute.function(
secrets=[
Secret.from_env("OPENAI_API_KEY"),
Secret.from_integration("prod_postgres"),
],
)
def call_api(prompt: str) -> str:
openai_api_key = os.environ["OPENAI_API_KEY"]
database_url = os.environ["DATABASE_URL"]
headers = {"Authorization": f"Bearer {openai_api_key}"}
db_host = urlparse(database_url).hostname
# Pass headers to your OpenAI-compatible client and database_url to
# your Postgres client.
return f"ready to call OpenAI for {prompt!r} and log to {db_host}"
Securing Sandboxes covers the identity and networking controls available for production workloads: workload identity federation (OIDC-compliant per-sandbox credentials), the MCP Gateway for proxying tool-use APIs without exposing real credentials, network policies for restricting egress, and WireGuard tunnels for private connectivity between workloads.