# Deep Coding Agents
source: https://docs.chalk.ai/docs/compute/deep-coding-agents

## Run coding agents like OpenCode in persistent Chalk scaling groups.

### 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 deploy a scaling group, install your agent, and connect
from a browser or terminal.

This tutorial walks through deploying OpenCode in a Chalk scaling group.
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 Image, ScalingGroup

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 Image, ScalingGroup

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

scaling_group = ScalingGroup(
    image=opencode_image,
    name="opencode-server",
    env={
        "OPENAI_API_KEY": "sk-...",        # your LLM provider key
        "GH_TOKEN": "ghp_...",             # for private repos
    },
    port=OPENCODE_PORT,
    min_replicas=0,
    max_replicas=1,
    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}",
    ],
).deploy().wait_ready()

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

try:
    time.sleep(43200)  # 12 hours
except KeyboardInterrupt:
    pass
finally:
    scaling_group.delete()
```

### Deploy it

```
python deploy_opencode.py
```

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

### Manage a running scaling group

You can reconnect to a deployed scaling group by name:

```
from chalkcompute import ScalingGroup

# Reconnect to the deployed scaling group
scaling_group = ScalingGroup.from_name("opencode-server")

print(scaling_group.web_url)

# Delete when done
scaling_group.delete()
```

### Pass files with volumes

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

```
from chalkcompute import Image, ScalingGroup, Volume

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

scaling_group = ScalingGroup(
    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,
    min_replicas=0,
    max_replicas=1,
    volumes=[("agent-config", "/root/.config/opencode")],
    entrypoint=["bash", "-c", "/root/.opencode/bin/opencode serve --hostname=0.0.0.0 --port=4096"],
).deploy().wait_ready()
```

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





