Overview

Deep coding agents — long-running AI sessions that clone a repo, explore the codebase, and write code — need more compute than a laptop and a stable environment that survives disconnects. Chalk Compute lets you spin up a container, install your agent, and connect from a browser or terminal.

This tutorial walks through deploying OpenCode in a Chalk container. The same pattern works for any agent that runs as a server process (Aider, Continue, etc.).


Define the image

Build an image with curl, git, and opencode baked in. Chalk caches the built image, so subsequent launches skip the install step entirely.

from chalkcompute import Container, Image

opencode_image = (
    Image.base("python:3.12-slim")
    .run_commands(
        "apt-get update -qq && apt-get install -y -qq curl git",
        "curl -fsSL https://opencode.ai/install | bash",
    )
)

Write the deploy script

Create a file called deploy_opencode.py:

import time
from chalkcompute import Container, Image

opencode_image = (
    Image.base("python:3.12-slim")
    .run_commands(
        "apt-get update -qq && apt-get install -y -qq curl git",
        "curl -fsSL https://opencode.ai/install | bash",
    )
)

OPENCODE_PORT = 4096

container = Container(
    image=opencode_image,
    name="opencode-server",
    env={
        "OPENAI_API_KEY": "sk-...",        # your LLM provider key
        "GH_TOKEN": "ghp_...",             # for private repos
    },
    port=OPENCODE_PORT,
    entrypoint=[
        "bash", "-c",
        "git clone --depth 1 https://github.com/your-org/your-repo.git /root/code"
        " && /root/.opencode/bin/opencode serve"
        "    --hostname=0.0.0.0"
        f"   --port={OPENCODE_PORT}",
    ],
).run()

print(f"Web UI: {container.info.web_url}")
print("Press Ctrl-C to stop.")

try:
    time.sleep(43200)  # 12 hours
except KeyboardInterrupt:
    pass
finally:
    container.stop()

Deploy it

chalk compute deploy deploy_opencode.py
# ✓ Container created successfully
# Container ID: a3f18c62-7d9b-4a1e-b824-91c5de07f3a8
# Name: opencode-agent
# Status: Running
# Pod Name: chalk-container-opencode-agent
# URL: https://a3f18c62-7d9b-4a1e-b824-91c5de07f3a8.compute.chalk.ai

The command builds the image (first run only), starts the container, and prints a URL you can open in your browser. The coding agent is now running with full cloud compute behind it.


Interact with a running container

You can also manage containers programmatically after they start:

from chalkcompute import Container

# Reconnect to a running container by name
container = Container.from_name("opencode-server")

# Execute commands inside it
result = container.exec("ls", "/root/code")
print(result.stdout_text)

# Stop when done
container.stop()

Pass files with volumes

Use a Volume to share configuration or model files with the container without baking them into the image:

from chalkcompute import Container, Image, Volume

vol = Volume(name="agent-config")
vol.put_file("opencode.json", '{"model": "claude-sonnet-4-20250514", "provider": "anthropic"}')

container = Container(
    image=Image.base("python:3.12-slim").run_commands(
        "apt-get update -qq && apt-get install -y -qq curl git",
        "curl -fsSL https://opencode.ai/install | bash",
    ),
    name="opencode-with-config",
    port=4096,
    volumes={"agent-config": "/root/.config/opencode"},
    entrypoint=["bash", "-c", "/root/.opencode/bin/opencode serve --hostname=0.0.0.0 --port=4096"],
).run()

The volume is mounted at /root/.config/opencode so the agent picks up your configuration on startup.