# Deploy from git

Covers: deploying an agent from a git repository, on the dashboard or from code, with its runtime, shape and keys.

For: developers who have a repository and want it running as an instance.

Point poema cloud at a repository on GitHub or GitLab, and it runs your agent on a fresh clone of a branch. You can do it
on the dashboard in a few clicks, or from code with the same result.

## Deploy from the dashboard

1. Open [New instance](https://client-test.poema.dev/dashboard/new) and pick how it starts: a ready-made agent (Claude Code, which poema's images
   carry; Codex, Gemini CLI, Pi and Hermes, each on an image of its own) or your own command, a shell on one of the
   runtimes below.
2. Give it a name, an optional repository's https URL and a branch (or its default one), an optional description and a
   Model where the image takes them, and a shape.
3. Under Advanced, set its runtime (Claude Code's and Shell's, as picked), its start command (Shell's; an agent always starts with its image's own) and its environment.

The instance clones the head of the branch into `repo` (an empty directory with no repository), then runs the start
command there. Its page shows its phase and status, the commit it runs, a timeline of what happened to it and, while it
runs, its log; Reset deletes it and starts it again from its spec, with a fresh clone of the branch if it has a repository.

> **Note:** There is no setup command for now: put install steps at the head of the start command.

![New instance, step 1, Pick an agent: the choices Agent and Your own command, and the agents Claude Code, Codex, Gemini CLI, Pi and Hermes, each with the model key it needs.](https://client-test.poema.dev/docs/img/new.png)

## Runtimes and shapes

- Ubuntu 24.04, the default, and Debian 13 slim (`agent-minimal`): poema's own images,
  each with git, curl, jq and Claude Code, Python 3 on the first and ripgrep on the second.
- Python 3.12 and Node 22: the official `python:3.12-bookworm` and `node:22-bookworm` images, pinned to
  one build each, `python@sha256:dbbe4ceb97851e2e5fa83798b239811f871cb743b259ba3563737349f6bcfaa0` and
  `node@sha256:363e1587494626837fa7f9a23bdb453d13b0ff3c67c705c2805cfc69c2d2fad7`, which poema's hosts hold with git, curl, jq and Claude Code added.
  To install a clone's packages, begin the start command with `python -m venv .venv && .venv/bin/pip install -r requirements.txt` or `npm ci`.
  A host starts no other runtime.
- Shapes S 1 vCPU and 1 GiB, M 2 vCPU and 2 GiB, L 2 vCPU and 4 GiB.

## Private repositories

On the [Keys](https://client-test.poema.dev/dashboard/secrets) page, paste a GitHub fine-grained personal access token for the
repositories your instances clone, with Contents read-only, or read and write if your agent pushes. The instance never
holds it: poema adds it to its requests to GitHub on their way out. The GitHub token works for git over HTTPS and the
GitHub API. Saving also updates existing instances;
if the form says the key is saved but the instances do not have it yet, save it again to retry. An instance given a
GitHub key of its own uses that key instead ([Secrets and keys](https://client-test.poema.dev/docs/secrets.md)). The token is not shown again.

> **Note:** GitLab repositories are public ones for now.

## MCP servers and skills

For an agent that reads them (Claude Code), New instance takes MCP servers, one per line: a name and the URL of a remote
server, or a name and the command that starts one in the instance. It writes them for the agent to find, and the agent
uses no others. A remote server's host has to be on [Network](https://client-test.poema.dev/dashboard/network), as the instance reaches it through
poema. GitHub's server is `api.githubcopilot.com`: add a key for that host on [Keys](https://client-test.poema.dev/dashboard/secrets).

Skills are repositories on GitHub or GitLab with a `SKILL.md` at their root, which the instance clones into
`repo/.claude/skills`. Another agent or Shell does not read them, and New instance refuses them.
Your organization can offer skills and servers to every instance too, and an instance starts with them
([The library](https://client-test.poema.dev/docs/library.md)). These are the servers and skills of the agent in the instance;
[poema-mcp](https://client-test.poema.dev/docs/mcp.md) is for the agent that drives poema.

## Access from your machine

With Access from your machine on, an instance is open to you in four ways:

- **Open, In this browser:** its agent in a terminal, and **Shell** beside it a plain shell (an instance of Shell has the
  shell alone). When the agent exits, the plain shell shows in its place. A suspended instance opens too, and resumes.
- **Continue task:** for a Claude Code instance given a task, in place of In this browser. Its Claude Code opens on the
  task's own conversation, in the task's folder (a copy of it while the task still runs), where you can go on with it.
- **Files:** the tab on its page.
- **From a shell:** `poema terminal NAME`, `poema exec NAME` and `poema forward NAME`, with your API key, and the Python
  SDK for its files.

The agent images start with it on and stay up for it when they have no description to work on. Shell stays up doing
nothing, for you to work in.

### In VS Code or Cursor

Such an instance opens in VS Code or Cursor too: VS Code and Cursor in its Open menu open it in the editor's Remote-SSH, its
files, terminals and debugger the instance's, through poema's editor extension, which asks first. The extension
signs in through this site (Poema: Sign In, with this site's address) or uses `poema login`'s key, and needs the
editor's Remote-SSH extension and OpenSSH's `ssh`. `poema ssh NAME` and `poema code NAME` do the same from a shell, and
`poema ssh-config --write` puts one `Host *.poema` block in `~/.ssh/config`, after which `ssh NAME.NAMESPACE.poema`, `scp`
and `sftp` reach any instance with Access from your machine. The
menu copies one line that runs `poema ssh NAME` from your terminal: the first time, it installs poema's command line from this
site in `~/.poema/cli` (on Node.js 22.19 or later), and it signs in at this site when it is not.

```
curl -fsSLO https://client-test.poema.dev/dl/poema-vscode-0.1.0.vsix
code --install-extension poema-vscode-0.1.0.vsix    # or: cursor --install-extension poema-vscode-0.1.0.vsix
```

## What the agent may do

A remote MCP server's tools are limited in the library ([The library](https://client-test.poema.dev/docs/library.md)). For the servers an instance runs
itself and for the agent's own tools (Bash, WebFetch and so on), New instance's **Agent permissions** turn off what Claude Code may do (run shell commands, change files, use the
web, start sub-agents, schedule work), or a preset of them such as Read-only, and under Individual tools any one of its
tools or an MCP server's (`mcp__server__tool`). Claude Code drops those when it starts.

> **Note:** Agent permissions are advisory: another agent, or a shell in the instance, is not limited by them, and
> removing WebFetch does not stop network access, which the hosts of [Network](https://client-test.poema.dev/dashboard/network) do.

The instance's page lists the MCP servers it has and, on a click, the tools each offers; listing starts the servers, so
it needs the instance to be running.

Claude Code with a task acts without asking (Auto mode), using only the tools its permissions leave it. New instance's **Mode** picker changes that: **Accept edits**, **Plan** or **Ask first**. Codex has Default, Edit files and Run everything; Gemini CLI has Default, Plan, Accept edits and Run everything; Pi and Hermes have no mode. **Common flags** adds one flag that was tried with the agent, and **Custom flags**, under Advanced, takes any other flag its command line accepts. Flags go onto its command line as written, after poema's own, the mode's and the common flag's, and are stored as plain text: no secrets. Gemini CLI's command trusts its folder (`--skip-trust`), as it does not start otherwise, so a repository's own `.gemini/settings.json` applies.

## Limits

- The start command 4 KiB.
- At most 32 environment variables, none of those poema sets (`POEMA_*`, `GIT_CONFIG*`, the proxies', the CA bundle's,
  `HOME`, `PATH` and the models'). Their values are plain text in the instance's spec, which your API keys read: a
  model's key goes in a Model.
- Sessions of up to 60 minutes on Free and 600 on Pro. At its end an instance is suspended, not deleted, and one left
  suspended for 14 days is deleted. So an agent that must always answer, such as a support bot, stops at the end of each
  session until you resume it.
- Each instance takes two of your plan's objects, its Task and its Workspace, and deleting it frees both.
- A Model budget, which New instance takes for an instance with a Model, is what one run of it may spend on model calls:
  poema refuses its calls past it, as it does past your organization's budget ([Plans, limits and billing](https://client-test.poema.dev/docs/plans.md#model-budget)).
- It reaches the free tier's hosts ([Concepts](https://client-test.poema.dev/docs/concepts.md)), and the hosts of your own you list on
  [Network](https://client-test.poema.dev/dashboard/network) too. That page shows them, and each instance's page shows what it was refused, with an
  Allow button where your plan takes hosts of its own.

## The same from code

New instance writes a Workspace that clones the repository and a Task that runs your start command in the clone. The
code below does the same with names of your own: the dashboard rewrites its own Gateway, `portal`, whenever your keys
change. With your key:

Python:

From the [Python SDK](https://client-test.poema.dev/docs/python.md). Set `GITHUB_TOKEN` and `ANTHROPIC_API_KEY` in your shell first:

```
import os
from poema import Poema

p = Poema()
p.set_secret("github", {"token": os.environ["GITHUB_TOKEN"]})
p.set_secret("anthropic", {"api-key": os.environ["ANTHROPIC_API_KEY"]})
p.apply({"kind": "Model", "metadata": {"name": "claude-sonnet-5-5"},
         "spec": {"provider": "anthropic", "model": "claude-sonnet-5-5", "secretKey": {"name": "anthropic", "key": "api-key"}}})
p.apply({"kind": "Gateway", "metadata": {"name": "git"}, "spec": {"egress": {"allowlist": {"hosts": [
    {"host": "github.com", "port": 443, "credential": {
        "secretKey": {"name": "github", "key": "token"}, "type": "basic", "username": "x-access-token"}},
    {"host": "pypi.org", "port": 443},
    {"host": "files.pythonhosted.org", "port": 443},
]}}}})
p.apply({"kind": "Workspace", "metadata": {"name": "my-agent"},
         "spec": {"git": [{"name": "repo", "repo": "https://github.com/you/my-agent", "branch": "main", "depth": 1}]}})
script = "export HOME=\"$PWD/.home\" PIP_NO_CACHE_DIR=1 && mkdir -p \"$HOME\" && mkdir -p repo && cd repo && { [ ! -e .git ] || git rev-parse HEAD; } && t() { if command -v timeout >/dev/null; then timeout 900 \"$@\"; else \"$@\"; fi; } && { [ -e ../.setup-done ] || { t bash -c -- \"$0\" && touch ../.setup-done; }; } && exec bash -c -- \"$1\""
t = p.create_task(
    "my-agent",
    ["bash", "-c", script, "python -m venv .venv && .venv/bin/pip install -r requirements.txt", ".venv/bin/python main.py"],
    image="python@sha256:dbbe4ceb97851e2e5fa83798b239811f871cb743b259ba3563737349f6bcfaa0",
    workspaces=["my-agent"],
    gateway="git",
    model="claude-sonnet-5-5",
    resources={"requests": {"cpu": "1", "memory": "1Gi"}, "limits": {"cpu": "1", "memory": "1Gi"}},
)
print(t.logs())
```

CLI:

From the [CLI](https://client-test.poema.dev/docs/cli.md), with your GitHub token in `github-token.txt` and your Anthropic key in `anthropic-key.txt`:

```
poema secret set github token=@github-token.txt
poema secret set anthropic api-key=@anthropic-key.txt
poema apply -f - <<'EOF'
kind: Model
metadata: {name: claude-sonnet-5-5}
spec:
  provider: anthropic
  model: claude-sonnet-5-5
  secretKey: {name: anthropic, key: api-key}
EOF
poema apply -f - <<'EOF'
kind: Gateway
metadata: {name: git}
spec:
  egress:
    allowlist:
      hosts:
        - host: github.com
          port: 443
          credential: {secretKey: {name: github, key: token}, type: basic, username: x-access-token}
        - {host: pypi.org, port: 443}
        - {host: files.pythonhosted.org, port: 443}
EOF
poema apply -f - <<'EOF'
kind: Workspace
metadata: {name: my-agent}
spec:
  git:
    - {name: repo, repo: https://github.com/you/my-agent, branch: main, depth: 1}
EOF
poema apply -f - <<'EOF'
kind: Task
metadata: {name: my-agent}
spec:
  image: python@sha256:dbbe4ceb97851e2e5fa83798b239811f871cb743b259ba3563737349f6bcfaa0
  command:
    - bash
    - -c
    - 'export HOME="$PWD/.home" PIP_NO_CACHE_DIR=1 && mkdir -p "$HOME" && mkdir -p repo && cd repo && { [ ! -e .git ] || git rev-parse HEAD; } && t() { if command -v timeout >/dev/null; then timeout 900 "$@"; else "$@"; fi; } && { [ -e ../.setup-done ] || { t bash -c -- "$0" && touch ../.setup-done; }; } && exec bash -c -- "$1"'
    - python -m venv .venv && .venv/bin/pip install -r requirements.txt
    - .venv/bin/python main.py
  workspaces: [{name: my-agent}]
  gateway: {name: git}
  model: {name: claude-sonnet-5-5}
  resources:
    requests: {cpu: "1", memory: 1Gi}
    limits: {cpu: "1", memory: 1Gi}
EOF
poema logs my-agent
```

Last checked: unreleased checkout.
