Python SDK
The Python SDK is the codeband module of the package codeband-sdk. You write pipelines with it, and its code server codeband-codeserver loads them and runs them for the daemon. It needs Python 3.12 or newer. Install codeband adds it to a factory, and Architecture shows where the code server runs.
Pipeline code imports the package as cb:
import codeband as cbA factory
Section titled “A factory”A factory is a folder with a pyproject.toml that lists its pipelines under [tool.codeband], and one package that holds the pipelines, the agents and the prompt template of each agent. codeband init writes one, and every factory has this layout:
my-pipelines/├── pyproject.toml lists the pipelines under [tool.codeband]└── my_pipelines/ ├── pipelines/ │ └── implement.py the pipeline, its stages and the types of its human steps ├── agents/ │ ├── implementer.py the agent, its input type and its output type │ └── implementer.md its prompt template ├── function_steps/ │ └── github.py the function steps that reach one outside system └── models.py the types that more than one pipeline or agent uses| Rule | |
|---|---|
| The package | Named after the folder, with _ in place of -. It holds everything that a pipeline imports, so you can publish it as it is |
| Pipelines | One module for each pipeline in pipelines/. Only the list in [tool.codeband] makes a function a pipeline, and the list can also name a pipeline of a package that someone else publishes |
| Agents | One module for each agent in agents/, with its prompt template next to it. An agent that needs more files becomes the folder agents/NAME/, and its import path stays the same |
| Function steps and shared types | Add function_steps/ with your first function step and models.py with your first type that two pipelines or agents use |
codeband init writes these files into a new factory:
| File | Holds |
|---|---|
pyproject.toml |
The project name from the folder name, requires-python = ">=3.12", the dependency codeband-sdk, package = false under [tool.uv] and the pipeline implement under [tool.codeband]. A codeband binary that is built from a release pins codeband-sdk to its own version |
.python-version |
3.12 |
.gitignore |
__pycache__/ |
README.md |
Where each kind of file goes, and the commands to start codeband dev, start a run and add a pipeline or an agent |
PACKAGE/pipelines/implement.py |
The pipeline implement, whose one parameter instruction is the field of its run input. It runs one agent step of implementer and ends the run with the code change of that agent step, with the first line of the instruction as its title and the summary as its description |
PACKAGE/agents/implementer.py |
The agent implementer on cb.ClaudeCode with the default model, the tools Read, Glob, Grep, Edit and Write, and access="write". Its input ImplementerInput holds instruction, and its output ImplementerOutput holds summary |
PACKAGE/agents/implementer.md |
The prompt template, which shows {{ input.instruction }} and asks for the summary |
codeband new pipeline writes a pipeline of the same form that ends the run with no code change, and codeband new agent an agent of the same form as implementer. Each package folder also gets an empty __init__.py. The names of the types are the CamelCase form of the name: codeband new agent code_reviewer writes CodeReviewerInput and CodeReviewerOutput. The package is the folder named after [project] name, with _ in place of -.
The daemon knows a factory under a name that codeband.toml or codeband dev gives it, and names each pipeline as FACTORY/PIPELINE, such as py-factory/intake. The code server never learns that name.
The code server loads every pipeline that the list names, from any layout. This factory has the pipeline fix_typo and its agent fixer:
fixes/├── pyproject.toml└── fixes/ ├── __init__.py ├── pipelines/ │ ├── __init__.py │ └── fix_typo.py └── agents/ ├── __init__.py ├── fixer.md └── fixer.py[project]name = "fixes"version = "0.1.0"requires-python = ">=3.12"dependencies = ["codeband-sdk"]
[tool.uv]package = false
[tool.codeband]pipelines = ["fixes.pipelines.fix_typo:fix_typo"]Fix this problem in the repository and commit the fix:
{{ input.problem }}import codeband as cb
class FixInput(cb.Model): problem: str
class FixOutput(cb.Model): title: str summary: str
fixer = cb.Agent( "fixer", input=FixInput, output=FixOutput, harness=cb.Fake( attempts=[ cb.FakeAttempt( write={"README.md": "# Hello, world\n"}, commit="Fix the greeting", output={"title": "Fix the greeting in README.md", "summary": "The greeting said 'Helo'."}, ) ] ),)import codeband as cb
from fixes.agents.fixer import FixInput, fixer
@cb.pipelinedef fix_typo(problem: str) -> cb.RunResult | None: """Ask the fixer for one fix and end the run with it.""" agent_step = fixer.do(FixInput(problem=problem))
change = cb.CodeChange(commit=agent_step.commit, title=agent_step.output.title, description=agent_step.output.summary) return cb.RunResult(code_change=change)The agent fixer runs on the fake harness, which scripts each attempt and runs no model. Its agent step writes README.md, commits it and returns its step output. The pipeline ends the run with that commit as its code change. With the code server started in fixes/ and a daemon running, a run in a target repository whose README.md says # Helo, world writes a patch file:
$ codeband run --input '{"problem": "README.md says Helo"}' fix_typoStarted run 423vx3178p/home/you/greeter/423vx3178p.patchNames at a glance
Section titled “Names at a glance”| Name | Kind | Section |
|---|---|---|
cb.pipeline, cb.Pipeline |
Decorator, class | Pipelines |
cb.Model |
Base class | Pipelines |
cb.RunResult, cb.CodeChange, cb.NewTicket |
Models | Pipelines |
cb.Ticket |
Model | Pipelines |
cb.Stop |
Exception | Pipelines |
cb.Stage |
Class | Stages |
cb.function_step, cb.FunctionStep |
Decorator, class | Function steps |
cb.FunctionStepFailedError |
Exception | Function steps |
cb.shell_step, cb.ShellStep |
Function, model | Shell steps |
cb.Agent |
Class | Agents and agent steps |
cb.AgentStep |
Dataclass | Agents and agent steps |
cb.Handle |
Dataclass | Agents and agent steps |
cb.gather |
Function | Agents and agent steps |
cb.AgentStepFailedError |
Exception | Agents and agent steps |
cb.MayAsk |
Base class | Agents and agent steps |
cb.run_head, cb.start_commit |
Functions | Agents and agent steps |
cb.Harness, cb.ClaudeCode, cb.Fake, cb.FakeAttempt, cb.FakeFailure, cb.FakeToolCall |
Type, models | Harnesses |
cb.human_step |
Function | Human steps |
cb.Question, cb.Questions, cb.Answers |
Models | Human steps |
cb.scorer, cb.Scorer |
Decorator, class | Scorers |
cb.Score, cb.ScoredRun, cb.ScoredStep |
Model, dataclasses | Scorers |
cb.DefinitionError |
Exception | Definition errors |
codeband.testing.call_pipeline, PipelineCall, Step, exited, StepOutputError, START_COMMIT |
Function, dataclasses, function, exception, constant | Tests |
Pipelines
Section titled “Pipelines”@cb.pipeline
Section titled “@cb.pipeline”def pipeline(fn: Callable[P, RunResult | None]) -> Pipeline[P]def pipeline(*, stages: Sequence[cb.Stage] = (), sandbox: str = "default") -> Callable[[Callable[P, RunResult | None]], Pipeline[P]]Makes a function a pipeline. The pipeline’s name is the function’s name, and its description is the function’s docstring.
Each parameter of the function is one field of the run input: its name is the field’s name, its type is the field’s type and its default is the field’s default. A parameter without a default is a required field. The run input is a JSON object with exactly these fields, and a function without parameters takes the empty object {}. A pipeline that starts from a ticket has the parameter ticket: cb.Ticket:
@cb.pipelinedef ship_ticket( ticket: cb.Ticket, cycles: Annotated[int, Field(description="How many review cycles the run may take.")] = 3,) -> cb.RunResult | None: ...ship_ticket takes the run input {"ticket": {"id": "cb-42", "title": "Fix the login", "body": "…", "tags": ["bug"]}}, and cycles is then 3. A hint written as Annotated[TYPE, Field(description=...)], with Field from pydantic, is the description of the field in the run input’s JSON Schema, and the start form of the web interface shows it under the field. The code server checks a run input before the daemon records the run: a missing required field, a value of the wrong type and a field that is no parameter are errors that name the field, such as other and Extra inputs are not permitted.
| Signature | What happens |
|---|---|
*args or **kwargs |
cb.DefinitionError with pipeline NAME takes *args: str: each parameter is one named field of the run input, so a pipeline takes no *args and no **kwargs |
A positional-only parameter, before / |
cb.DefinitionError with pipeline NAME takes PARAMETER as positional only: each parameter is one named field of the run input |
| A parameter without a type annotation | cb.DefinitionError with parameter PARAMETER of pipeline NAME has no type |
The function returns a cb.RunResult to end the run with a code change, new tickets or both, or None to end it with nothing to deliver. A run result without a code change and without tickets ends the run the same as None. raise cb.Stop(reason) ends the run on purpose. Any other exception that the function does not catch fails the run with pipeline_error and the traceback. A return value of another type fails the run with pipeline NAME returned TYPE, want cb.RunResult or None, and a bare cb.CodeChange adds : return cb.RunResult(code_change=...).
@cb.pipeline(stages=[build, review]) declares the stages of the pipeline, in the order that a person who watches its runs sees them. Without stages, the pipeline has none.
@cb.pipeline(sandbox="go") names the sandbox definition in which every agent step and every shell step of the pipeline’s runs runs. The [sandbox.go] table of the daemon’s codeband.toml defines it. Without sandbox, the name is default. An agent, Agent.do, a shell step and a run fork take no sandbox. An empty name or a value that is not a string raises cb.DefinitionError with pipeline NAME names the sandbox VALUE, want the name of a sandbox definition.
The decorator registers nothing. A pipeline exists for the code server only when [tool.codeband] pipelines lists it (see [tool.codeband] settings).
Pipeline code runs again from the start on every invocation, a run replay of the pipeline in which each recorded step returns its recorded value. It must give the same steps in the same order each time. A value that differs between invocations, such as the clock, belongs in a function step.
cb.Pipeline
Section titled “cb.Pipeline”The object that @cb.pipeline returns. Calling it with the function’s arguments calls the function, so a test can run a pipeline as plain Python; the function steps in it then run as plain functions. A pipeline with shell steps, agent steps or human steps needs call_pipeline, which gives them their step outputs and answers. Test a pipeline without a daemon shows both.
| Attribute | Type | Value |
|---|---|---|
name |
str |
The function’s name |
description |
str |
The function’s docstring, or empty |
input |
type[cb.Model] |
The type of the run input, with one field for each parameter of the function |
stages |
tuple[str, ...] |
The names of the declared stages, in declared order. Empty for a pipeline without stages |
sandbox |
str |
The name of the sandbox definition, default for a pipeline that names none |
fn |
Callable |
The decorated function |
cb.Model
Section titled “cb.Model”The base class of the types of run input fields, agent inputs and step outputs, and human step questions and answers. It is a pydantic BaseModel that refuses unknown fields, so a misspelled field is an error, and it is frozen, because recorded values never change.
cb.RunResult
Section titled “cb.RunResult”class RunResult(cb.Model): code_change: CodeChange | None = None tickets: list[NewTicket] = []What a run ends with, its run result: a code change, new tickets or both. A pipeline returns it. Both fields are empty by default, and cb.RunResult() ends the run the same as None. The run journal records the new tickets, and codeband run, codeband show and the page for the run show the title of each one and where it went.
The engine delivers each part to its run result destination: the code change to a patch file or a pull request, the new tickets to ticket files or to GitHub issues.
return cb.RunResult( code_change=cb.CodeChange(commit=agent_step.commit, title="Fix the login", description=agent_step.output.summary), tickets=[cb.NewTicket(title="Log failed logins", body="The fix showed that failed logins leave no trace.", tags=["follow-up"])],)A pipeline returns no other data: a subclass of cb.RunResult crosses the protocol as a cb.RunResult.
cb.Ticket
Section titled “cb.Ticket”class Ticket(cb.Model): id: str title: str body: str tags: list[str] url: str | None = None extra: dict[str, dict[str, JsonValue]] = {}A ticket that a run starts from, as the trigger copied it into the run input. A pipeline that starts from a ticket has the parameter ticket: cb.Ticket. id is the ticket’s ID in its ticket system, body is the ticket’s Markdown without its title, and url is the address of the ticket’s web page, when it has one. extra holds data of ticket systems, each under its name, with the field names of that system’s API, such as extra["github"]["milestone"]. A pipeline that reads extra works with that ticket system only. A later edit of the ticket does not reach the run.
cb.NewTicket
Section titled “cb.NewTicket”class NewTicket(cb.Model): title: str body: str tags: list[str] extra: dict[str, dict[str, JsonValue]] = {}A ticket that a run ends with, in the tickets of a cb.RunResult. body is Markdown without the title. A new ticket has no ID: the ticket system gives it one when the daemon files it. A run that fails, stops or is cancelled has no new tickets.
extra holds data of ticket systems, each under its name, with the field names of that system’s API. The run result destination of one ticket system reads its own part and ignores the others: GitHub issues read extra["github"], and ticket files ignore all of it. cb.NewTicket(title="Greet in French", body="", tags=[], extra={"github": {"assignees": ["octocat"]}}) gives an issue assigned to octocat.
cb.CodeChange
Section titled “cb.CodeChange”class CodeChange(cb.Model): commit: str title: str description: str branch_label: str | None = NoneThe code change that a run ends with: a commit of the target repository, a title and a description. A pipeline returns it as the code_change of a cb.RunResult. commit is usually agent_step.commit or cb.run_head(). The engine writes the commit of the code change with the title and the description as its message; a code change whose files equal those of the run’s start commit ends the run with no code change.
The engine delivers the code change to its run result destination: a patch file, which codeband run writes and prints, or with codeband run --pr a pull request, whose URL it prints. The pull request has the title and the description, and its branch holds the commits from the run’s start commit to commit.
branch_label names the branch of a pull request, such as after a ticket: branch_label="cb-42" gives the branch codeband/cb-42-8qqf0w, the label and the first 6 characters of the run ID. Without a label, the branch is codeband/RUN-ID. A patch file ignores it. A label holds letters, digits, ., _, - and / between parts, each part starts with a letter, a digit or _, and the label must fit in a git branch name; any other label raises pydantic.ValidationError where the pipeline builds the cb.CodeChange.
cb.Stop
Section titled “cb.Stop”class Stop(Exception): def __init__(self, reason: str) -> NoneRaise it in a pipeline to end the run on purpose. The run ends stopped, not failed, and codeband run prints stopped: followed by reason. The attribute reason holds the text.
Stages
Section titled “Stages”cb.Stage
Section titled “cb.Stage”class Stage: def __init__(self, name: str) -> NoneA named part of a pipeline, a stage, such as build or review. Declare it with @cb.pipeline(stages=[...]) and enter it with a with block. An empty name raises ValueError with a stage name must not be empty. The attribute name holds the name.
build = cb.Stage("build")review = cb.Stage("review")
@cb.pipeline(stages=[build, review])def fix_issue(ticket: cb.Ticket) -> cb.RunResult | None: with build: fix = implementer.do(Task(ticket=ticket.body))
with review: reviewer.do(Task(ticket=ticket.body))
return cb.RunResult(code_change=cb.CodeChange(commit=fix.commit, title=fix.output.title, description=fix.output.summary))Every agent step, shell step and human step that starts inside the block, and every function step that runs inside it, belongs to the stage, also when a function that the block calls asks for it. The run journal records the stage on the entry that starts the step, as stage of stepStarted. A step outside every block has no stage. Two blocks can enter the same stage. Outside a run, the block does nothing.
| Rule | What breaks it |
|---|---|
A pipeline declares each stage once, as a cb.Stage |
cb.DefinitionError when the code server loads the factory: pipeline NAME declares stage 'STAGE' twice, or pipeline NAME declares VALUE as a stage, want a cb.Stage |
| A run enters only a stage that its pipeline declares | cb.DefinitionError when the code server loads the factory, for a with block on a stage variable: pipeline NAME enters stage 'STAGE' at PATH:LINE, which it does not declare in @cb.pipeline(stages=[...]). A stage that the code looks up at run time fails the run with definition_error: the pipeline enters stage 'STAGE', but it declares 'A', 'B' |
| A stage block is never inside another stage block | The run fails with definition_error: the block of stage 'INNER' is inside the block of stage 'OUTER': a run is in one stage |
Function steps
Section titled “Function steps”@cb.function_step
Section titled “@cb.function_step”@cb.function_stepdef received_at() -> str: ...
@cb.function_step(timeout=timedelta(seconds=30))def post_summary(text: str) -> None: ...Makes a function a function step: a function of pipeline code whose value the engine records. Use a function step for side effects outside the target repository and for values that differ between runs, such as the clock.
| Parameter | Type | Default | Description |
|---|---|---|---|
timeout |
timedelta |
5 minutes | After this time, pipeline code gets cb.FunctionStepFailedError with the type TimeoutError |
The function step’s name is the function’s name. Its first call in a run runs the function in the code server, with the code server’s environment variables, and the engine records the value. Every later invocation returns the recorded value without running the function. Arguments and the return value must be JSON values or cb.Models. The return type annotation decodes the recorded value.
A function step that raises, or that runs longer than its timeout, raises cb.FunctionStepFailedError in pipeline code. A function step that times out is not stopped: it runs on in the background of the code server. Function steps run at least once: a crash after the side effect and before the record runs the function step again, so write side effects that are safe to repeat. Handle a function step that fails or times out shows a timeout, a retry and a side effect that is safe to repeat.
Outside a run, calling a function step calls the function. A function step that calls another function step runs it as a plain function.
cb.FunctionStep
Section titled “cb.FunctionStep”The object that @cb.function_step returns. It has the attributes name (str), timeout (timedelta) and fn, the decorated function.
cb.FunctionStepFailedError
Section titled “cb.FunctionStepFailedError”class FunctionStepFailedError(Exception): step_id: str type: str message: strA function step raised or timed out. step_id is the function step’s step ID, such as post_summary#0; type is the name of the exception type that the function step raised, or TimeoutError; message is the exception’s text. Its text is function step STEP_ID failed: TYPE: MESSAGE, for example function step post_summary#0 failed: TimeoutError: the function step did not finish within its timeout. Pipeline code may catch it; uncaught, it fails the run. Handle a function step that fails or times out catches it.
Shell steps
Section titled “Shell steps”cb.shell_step
Section titled “cb.shell_step”def shell_step( argv: Sequence[str], *, name: str, at: str | None = None, timeout: timedelta = timedelta(minutes=10), env: Sequence[str] = (),) -> ShellStepRuns a program in a new workspace and returns how it ended. The engine runs the program, not the code server. No shell reads argv: write ["sh", "-c", "..."] to use one. The workspace holds the commit at, the run head by default. A shell step never commits and never moves the run head, and the engine discards what the program changes.
| Parameter | Type | Default | Description |
|---|---|---|---|
argv |
Sequence[str] |
required | The program and its arguments. Must not be empty |
name |
str |
required | Name of the shell step, matching [A-Za-z0-9_-]+. Its step IDs are NAME#N |
at |
str | None |
None |
Full ID of the commit to start at, 40 or 64 hex characters, in place of the run head |
timeout |
timedelta |
10 minutes | The engine sends SIGTERM to the program after this time. Must be positive |
env |
Sequence[str] |
() |
Names of environment variables whose values the program gets from the daemon’s environment. The run records the names, never the values |
The program also gets PATH, HOME and USER from the daemon’s environment, and before the variables of env, the variables of the [env] table of codeband.toml and the default login variables. What an agent step and a shell step get has the order. An agent step gets the same variables from codeband, but the Bash tool of Claude Code also reads your shell profile, so a tool such as asdf can pass in an agent step and fail in a shell step. Run problems has the fix. A non-zero exit code, a timeout, a missing environment variable or a variable of [env] without a value gives ok=False and never raises. An argument that is not valid raises ValueError. Outside a run, cb.shell_step raises RuntimeError with cb.shell_step runs only inside a run, except in a test that calls the pipeline with call_pipeline. Run a program in the target repository shows a call and how to read its result.
cb.ShellStep
Section titled “cb.ShellStep”The model that cb.shell_step returns.
| Field | Type | Description |
|---|---|---|
ok |
bool |
True when the program exited with code 0 within its timeout |
exit_code |
int | None |
None when the exit code is unknown: after a timeout, a signal, or when the program did not start |
timed_out |
bool |
True when the program ran longer than its timeout |
output_tail |
str |
The last 64 KiB of standard output and standard error, interleaved as the program wrote them |
changed_paths |
tuple[str, ...] |
Files that the program changed in its workspace, at most 1000 |
changed_paths_truncated |
bool |
True when the engine cut changed_paths at its limit |
Agents and agent steps
Section titled “Agents and agent steps”cb.Agent
Section titled “cb.Agent”class Agent[I: cb.Model, O: cb.Model]: def __init__( self, name: str, *, input: type[I], output: type[O], harness: cb.Harness, access: Literal["read", "write"] = "write", timeout: timedelta = timedelta(minutes=30), prompt: str | Path | None = None, leftovers: Literal["commit", "discard"] = "commit", ) -> NoneAn agent: a reusable role with a prompt template and a typed input and output, run on a harness. Define it at module level, in a module that a listed pipeline imports. The constructor reads no file; the code server reads and checks the prompt when it loads the factory.
| Parameter | Type | Default | Description |
|---|---|---|---|
name |
str |
required | Name of the agent, matching ^[A-Za-z0-9_-]+$. It is part of every agent step’s step ID, so renaming an agent breaks the resume of runs that have agent steps of it |
input |
subclass of cb.Model |
required | Model of the input. The prompt template reads it as input |
output |
subclass of cb.Model |
required | Model of the step output. Its JSON Schema goes to the harness |
harness |
cb.Harness |
required | Options of the harness that runs the agent steps, such as cb.ClaudeCode(...) |
access |
"read" or "write" |
"write" |
"write" moves the run head to the end commit of each agent step of do(); "read" leaves it. An agent step of start() never moves it |
timeout |
timedelta |
30 minutes | The engine stops an attempt after this time. Must be positive |
prompt |
str, Path or None |
None |
Path of the prompt template, relative to the module that defines the agent. None means NAME.md next to that module |
leftovers |
"commit" or "discard" |
"commit" |
"commit" commits the files that the agent changed and did not commit; "discard" drops them |
A value that is not valid raises cb.DefinitionError, such as agent name 'bad name' must match ^[A-Za-z0-9_-]+$.
An agent also holds its model, its permissions and its budgets. A budget limits the agent steps or the cost of an agent; going over it opens a human step. One agent step can run on another model than the agent’s.
Agent.do
Section titled “Agent.do”def do(self, input: I) -> cb.AgentStep[O]Runs one agent step and waits for its step output. In a run replay, it returns the recorded step output at once. The input must be an instance of the agent’s input type, or do raises TypeError. An agent step that ends without a step output raises cb.AgentStepFailedError. Outside a run, do raises RuntimeError with agent NAME: an agent step runs only in a pipeline that the code server runs, except in a test that calls the pipeline with call_pipeline.
An agent step whose agent cannot go on without a person ends with an agent question: the agent’s output type subclasses cb.MayAsk, and the agent returned questions. do returns that agent step like any other, with the questions in agent_step.output.questions. Pipeline code asks them at a human step with cb.Questions and answer=cb.Answers, and passes the answers to a new agent step. examples/hello does it in a loop, so the agent can ask again:
agent_step = implementer.do(ImplementerInput(instruction=instruction))while agent_step.output.questions: answers = cb.human_step("clarify", cb.Questions(questions=agent_step.output.questions), answer=cb.Answers) agent_input = ImplementerInput(instruction=instruction, clarifications=clarifications(agent_step.output.questions, answers)) agent_step = implementer.do(agent_input)Agent.start
Section titled “Agent.start”def start(self, input: I) -> cb.Handle[O]Starts a parallel agent step and returns a cb.Handle at once, without waiting for its step output. cb.gather() waits for it. The engine runs all the agent steps that a pipeline started at the same time, each attempt in its own workspace, with no limit on their number. Only agent steps start this way: shell steps, function steps and human steps have no start.
import codeband as cb
from fixes.agents.fixer import FixInput, fixer
@cb.pipelinedef fix_typo_twice(problem: str) -> cb.RunResult | None: """Ask the fixer for two fixes at the same time and end the run with the cheaper one.""" task = FixInput(problem=problem) first, second = cb.gather(fixer.start(task), fixer.start(task)) cheaper = min(first, second, key=lambda agent_step: agent_step.cost_usd)
change = cb.CodeChange(commit=cheaper.commit, title=cheaper.output.title, description=cheaper.output.summary) return cb.RunResult(code_change=change)The two agent steps are fixer#0 and fixer#1. A parallel agent step starts at the run head, or at the commit of using(at=), as it is when start is called, and it belongs to the stage of the block where start is called. It never moves the run head, also when its agent has access="write", so both agent steps of fixer start at the run’s start commit and neither sees the code of the other. Pipeline code picks the agent step it goes on with: it returns a run result with cb.CodeChange(commit=agent_step.commit, ...), as fix_typo_twice does, or starts the next agent step at that commit with using(at=agent_step.commit). codeband never merges the code of parallel agent steps on its own; a pipeline that wants the changes of several calls a merge function step.
A pipeline that returns, raises cb.Stop or raises another error while an agent step that it started has no step output waits for that agent step first. The run ends after every agent step that it started has ended, and pipeline code that never gathers an agent step never sees its step output or its failure.
The input must be an instance of the agent’s input type, or start raises TypeError. Outside a run, start raises RuntimeError with agent NAME: an agent step runs only in a pipeline that the code server runs, except in a test that calls the pipeline with call_pipeline.
cb.Handle
Section titled “cb.Handle”@dataclass(frozen=True)class Handle[O]: id: strA parallel agent step that agent.start() started. id is its step ID, such as fixer#1. Pass it to cb.gather() to get the agent step. A handle comes only from agent.start().
cb.gather
Section titled “cb.gather”def gather(*handles: cb.Handle[Any]) -> tuple[cb.AgentStep[Any], ...]Waits until every agent step of handles has ended, and returns their cb.AgentSteps in argument order, not in the order in which they ended. For up to four handles, the type of each agent step keeps the output type of its agent, so in fix_typo_twice, first.output has the type FixOutput. With more handles, the agent steps have the type cb.AgentStep[Any].
When one or more of the agent steps ended without a step output, gather raises the cb.AgentStepFailedError of the first failed agent step in argument order. It raises only after all the agent steps have ended. Pipeline code may catch it; uncaught, it fails the run. Outside a run, gather raises RuntimeError with cb.gather() works only in a pipeline that the code server runs, except in a test that calls the pipeline with call_pipeline.
Agent.using
Section titled “Agent.using”def using( self, *, at: str | None = None, harness: cb.Harness | None = None, leftovers: Literal["commit", "discard"] | None = None,) -> Agent[I, O]Returns a copy of the agent with other options for its agent steps. The name stays the same, so the copy’s agent steps count on with the agent’s step IDs.
| Parameter | Description |
|---|---|
at |
Start the agent steps at this commit instead of the run head |
harness |
Harness options in place of the agent’s |
leftovers |
What happens to the files that the agent did not commit |
cb.AgentStep
Section titled “cb.AgentStep”@dataclass(frozen=True)class AgentStep[O]: id: str output: O commit: str cost_usd: float changed_paths: tuple[str, ...] changed_paths_truncated: boolWhat one agent step produced. id is the agent step’s step ID, such as fixer#0. output is the step output, checked against the agent’s output type. commit is the end commit of the agent step; for an agent with access="write", the run head moves there after do(), and stays where it is after start(). cost_usd is the cost of the agent step’s attempts.
For an agent with access="read", commit is the agent step’s start commit and changed_paths lists the files that the agent changed, which the engine discards. Ignored files are not listed. After 1000 paths the engine cuts the list and sets changed_paths_truncated. For an agent with access="write", changed_paths is empty.
cb.AgentStepFailedError
Section titled “cb.AgentStepFailedError”class AgentStepFailedError(Exception): step_id: str kind: str message: strAn agent step ended without a step output. The run head does not move. kind is the attempt failure kind of the agent step’s last attempt, one of the kinds under cb.FakeFailure. Its text is agent step STEP_ID failed: KIND: MESSAGE, for example agent step fixer#0 failed: error: the model gave up. Pipeline code may catch it; uncaught, it fails the run.
cb.MayAsk
Section titled “cb.MayAsk”class MayAsk(cb.Model): questions: list[cb.Question] = []The base class of an agent’s output type that lets the agent ask a person instead of finishing its work. Subclass it in place of cb.Model, and declare the other fields as you need them, with or without defaults:
class ImplementerOutput(cb.MayAsk): title: str summary: strA step output with questions may leave out the other fields. Read only questions from it: a field that the agent left out raises AttributeError. A step output without questions must have every field without a default, or the code server rejects it and the attempt fails with invalid_output. The JSON Schema that the harness gets requires no field, so that an agent that asks can return only questions.
The engine then starts a new attempt of the agent step, as Attempts and retries describes.
A pydantic model validator with mode="after" on the output type also runs on a step output with questions, and there each field that the agent left out is None. Such a validator checks questions first and returns the output when it has any:
from typing import Self
from pydantic import model_validator
import codeband as cb
class ImplementerOutput(cb.MayAsk): title: str summary: str
@model_validator(mode="after") def check_title(self) -> Self: if self.questions: return self
if not self.title.strip(): raise ValueError("the title is empty")
return selfAn agent step ends with an agent question when its output has at least one question. Its run journal records it, and codeband run shows it as ✓ implementer#0 has questions after 41s, $0.12. An empty questions list is a step output like any other.
cb.run_head and cb.start_commit
Section titled “cb.run_head and cb.start_commit”def run_head() -> strdef start_commit() -> strcb.run_head() returns the run head: the commit where the next agent step or shell step starts unless another commit is named. It is the end commit of the run’s last agent step of do() whose agent may write, or the run’s start commit before one. A parallel agent step of start() never moves it. cb.start_commit() returns the run’s start commit. Outside a run, both raise RuntimeError, such as cb.run_head() works only in a pipeline that the code server runs, except in a test that calls the pipeline with call_pipeline.
Prompt templates
Section titled “Prompt templates”An agent’s prompt is a Markdown file in Jinja syntax, with loops and conditions, such as {% if input.problems %}. It renders in Jinja’s SandboxedEnvironment, with the agent step’s input as input, its only value. An undefined value is an error. Every {{ }} expression prints a string as it is, None as empty text and any other value as JSON indented by two spaces.
The code server checks only the syntax of the template when it loads the factory, and logs a warning for every name other than input.
| Mistake | Error |
|---|---|
| The template is not valid Jinja | cb.DefinitionError when the code server loads the factory: prompt PATH: line N: MESSAGE |
| The file cannot be read | cb.DefinitionError when the code server loads the factory: agent NAME: reading the prompt PATH: ERROR |
| An expression names a field that the input type lacks | jinja2.exceptions.UndefinedError when the agent step’s prompt renders, which fails the run: 'MODULE.TYPE object' has no attribute 'FIELD' |
Harnesses
Section titled “Harnesses”cb.Harness
Section titled “cb.Harness”The type of the harness parameter of cb.Agent: the options of every harness that an agent can run on. Each harness has its own options type, so a wrong option fails before a run starts.
The Python SDK has options for the Claude Code and Codex CLI harnesses, and for the fake harness.
cb.ClaudeCode
Section titled “cb.ClaudeCode”class ClaudeCode(cb.Model): model: str = "" effort: Literal["low", "medium", "high", "xhigh", "max"] | None = None tools: list[ClaudeTool] = ["Read", "Grep", "Glob"] allow: list[str] = []Options of the Claude Code harness. Each attempt of an agent step runs claude -p in its workspace, with the rendered prompt on standard input and the JSON Schema of the agent’s output type as the structured output.
| Field | Type | Default | Description |
|---|---|---|---|
model |
str |
"" |
Model alias or name, such as "sonnet" or "opus". Empty uses the default of Claude Code |
effort |
"low", "medium", "high", "xhigh", "max" or None |
None |
Reasoning effort. None uses the default of Claude Code |
tools |
list of tool names | ["Read", "Grep", "Glob"] |
Built-in tools that the agent can see: Bash, Edit, Glob, Grep, NotebookEdit, Read, Skill, Task, WebFetch, WebSearch and Write. Another name raises a validation error when the module loads |
allow |
list[str] |
[] |
Permission rules of Claude Code that approve tool calls, such as "Bash(go test *)" |
harness=cb.ClaudeCode(model="sonnet", tools=["Read", "Glob", "Grep", "Edit", "Write", "Bash"])Claude Code runs with --permission-mode dontAsk, so it denies every tool call that no rule approves. codeband adds three rules: Edit(//WORKSPACE/**) when tools holds Edit, which approves edits inside the workspace, named by its absolute path so that it holds after the agent runs cd, and Bash(git add *) and Bash(git commit *) when it holds Bash and the agent has access="write", so the agent can commit. An agent with access="read" gets no commit rules, because the engine discards its commits. Each attempt gets an empty Claude Code config folder, so your own Claude Code settings and login don’t apply. Claude Code and the commands of its agent get PATH, HOME and USER of the daemon’s environment, the variables of the [env] table of codeband.toml and the login, from [env] or else from CLAUDE_CODE_OAUTH_TOKEN or ANTHROPIC_API_KEY of the daemon’s environment. No other variable of the daemon’s environment reaches them. An agent step without a login, or without claude 2.1.330 or later on the PATH of the daemon, fails with the attempt failure kind setup.
cb.Fake
Section titled “cb.Fake”class Fake(cb.Model): attempts: list[cb.FakeAttempt]Options of the fake harness, which scripts each attempt of an agent step and runs no agent. Use it in tests and examples. attempts holds at least one entry. Attempt k of an agent step follows attempts[k], and the last entry repeats.
The engine retries a failed attempt depending on the kind of its attempt failure, so a list of attempts can script a failure followed by a success.
cb.FakeAttempt
Section titled “cb.FakeAttempt”What one attempt of the fake harness does, in this order: text, tool calls, write, commit, uncommitted, delay, then the end.
| Field | Type | Default | Description |
|---|---|---|---|
write |
dict[str, str] |
{} |
Files to write in the workspace, by path relative to its root |
commit |
str |
"" |
Commit message. When set, the fake commits every change in the workspace before it ends |
uncommitted |
dict[str, str] |
{} |
Files to write after the commit, by path relative to the workspace root. They stay uncommitted, as the attempt’s leftovers |
output |
JSON value or None |
None |
The step output. An attempt without output and without fail fails with invalid_output |
fail |
cb.FakeFailure or None |
None |
A failure in place of an output |
text |
list[str] |
[] |
Agent text, one agent transcript entry for each line |
tool_calls |
list[cb.FakeToolCall] |
[] |
Tool calls after text, each a tool use and its result in the agent transcript |
text_interval |
timedelta |
0 | Time to wait before each line of text and each tool call, except the first of them, so that an agent step’s agent transcript arrives over time |
delay |
timedelta |
0 | Time to wait before the attempt ends |
cost_usd |
float |
0.0 |
Cost that the attempt reports |
cb.FakeFailure
Section titled “cb.FakeFailure”class FakeFailure(cb.Model): kind: Literal["rate_limit", "crash", "api_error", "invalid_output", "timeout", "error", "setup"] message: str = ""How a scripted attempt fails. kind is the attempt failure kind, which cb.AgentStepFailedError.kind reports.
cb.FakeToolCall
Section titled “cb.FakeToolCall”class FakeToolCall(cb.Model): tool: str input: JsonValue = {} content: str = "" failed: bool = FalseA tool call that a scripted attempt reports in its agent transcript: a tool use with tool and input, then its tool result with content. failed=True marks the tool result as the one of a failed call, and content then says why. The fake runs no tool, so the call changes nothing in the workspace.
cb.FakeAttempt( text=["I list the files."], tool_calls=[cb.FakeToolCall(tool="Bash", input={"command": "ls"}, content="hello.txt\n")], output={"title": "Add hello.txt"},)Human steps
Section titled “Human steps”cb.human_step
Section titled “cb.human_step”def human_step[A](name: str, question: cb.Model, *, answer: type[A]) -> AAsks a person a typed question, a human step, and returns their answer as an answer. The human step’s first call in a run opens it, and the run waits until a person answers, in the terminal of codeband run or with codeband answer (see codeband CLI). The code server checks each answer against answer and its validators; the person sees a rejected answer’s error and answers again. Every later invocation returns the recorded answer.
| Parameter | Type | Description |
|---|---|---|
name |
str |
Name of the human step. Must not be empty and must not hold #. Its step IDs are NAME#N |
question |
cb.Model |
The question, such as a cb.Question |
answer |
type | Any type that pydantic validates, such as bool, an enum, str, int or a cb.Model |
if not cb.human_step("ship", cb.Question(text=f"Deliver '{agent_step.output.title}'?"), answer=bool): raise cb.Stop("a person rejected the fix")At this human step, codeband run prints:
Run r98mbjqqcm waits for an answer to human step ship#0. Answer it with: codeband answer r98mbjqqcm ship#0 --json '<answer>'Outside a run, cb.human_step raises RuntimeError with cb.human_step works only in a run, where a person can answer it, except in a test that calls the pipeline with call_pipeline. Answer a human step adds a human step to a pipeline and answers it.
cb.Question, cb.Questions and cb.Answers
Section titled “cb.Question, cb.Questions and cb.Answers”| Model | Fields | Description |
|---|---|---|
cb.Question |
text: str, options: list[str] = [] |
One question for a person. options holds suggested answers; empty means free text |
cb.Questions |
questions: list[cb.Question] |
A human step question that holds several questions. Ask it with answer=cb.Answers |
cb.Answers |
answers: list[str] |
One answer per question of a cb.Questions human step, in the same order |
The terminal shows each question of a cb.Questions human step with its numbered suggested answers. The human step rejects a cb.Answers whose number of answers differs from the number of questions, with give one answer per question: WANT answers, not GOT.
Scorers
Section titled “Scorers”A scorer judges one finished run and returns its scores. The code server serves the scorers that [tool.codeband] lists next to the pipelines, and the engine runs each of them when a run of the factory ends.
@cb.scorer
Section titled “@cb.scorer”def scorer( fn: Callable[[ScoredRun], Score | dict[str, Score] | None] | None = None, *, labels: Sequence[str] = (), sample_rate: float = 1.0,) -> ScorerMakes a function a scorer. The function gets a cb.ScoredRun and returns one cb.Score, which takes the name of the function, a dict of scores by name, or None when the run lacks the evidence for a score. A name that the function leaves out of its dict has no score for that run.
| Parameter | Type | Default | Description |
|---|---|---|---|
labels |
sequence of str |
() |
The fixed set of labels that a score of this scorer may have. A label outside it fails the scoring of that run |
sample_rate |
float |
1.0 |
The share of runs that the scorer scores, from 0.0 to 1.0. Set it below 1.0 for a scorer whose judge is an agent, to pay for fewer agent steps |
A scorer that calls do() of an agent, its judge, runs in a scoring run: a run of its own whose run journal records the judge’s agent steps and their cost. A scorer that calls no agent runs in the code server and records nothing.
Scorer shows a scorer that counts review cycles.
cb.Score
Section titled “cb.Score”class Score(cb.Model): value: float | bool | str explanation: str = "" unit: str | None = NoneOne score of a run. value is a number, a pass (True) or a fail (False), or a label of the scorer’s labels. unit names the unit of a number, such as USD, cycles or days. The dashboard shows the median of numbers, the share of passes and the share of each label.
cb.ScoredRun
Section titled “cb.ScoredRun”@dataclass(frozen=True)class ScoredRun: id: str pipeline: str status: str input: dict[str, Any] result: cb.RunResult | None steps: tuple[ScoredStep, ...] cost_usd: float started_at: datetime ended_at: datetime parent: str | NoneA read-only view of one finished run. pipeline is the name of the pipeline in its factory, such as ship_ticket. status is how the run ended: finished, stopped, failed or cancelled. parent is the run ID of the parent run of a run fork, and None for every other run.
cb.ScoredStep
Section titled “cb.ScoredStep”@dataclass(frozen=True)class ScoredStep: id: str kind: Literal["agent", "function", "shell", "human"] request: dict[str, Any] output: Any transcript: str | None cost_usd: float started_at: datetime ended_at: datetime | NoneOne step of a cb.ScoredRun, in the order the steps started. id is the step ID, such as implementer#0. request is the step request as the run journal records it, and output the step output. transcript is the agent transcript of an agent step’s last attempt as text, and None for other steps.
Built-in scorers
Section titled “Built-in scorers”The SDK scores every run with its built-in scorers, without an entry in [tool.codeband]. Scorer lists them with their values.
Names and step IDs
Section titled “Names and step IDs”Every step that pipeline code asks for has a step ID NAME#N, where N counts the calls of that name in the run from 0. A function step’s name is its function’s name; an agent, a shell step and a human step take theirs as an argument.
| Rule | What breaks it |
|---|---|
| No two function steps or agents share a name | cb.DefinitionError when the code server loads the factory: NAME is defined twice: as function step NAME in MODULE and as agent NAME |
| One name names one kind of step in a run | The run fails with definition_error: pipeline code uses the name 'NAME' for a function step and for a human step: give one of them another name |
| A recorded step keeps its kind, and a recorded agent step or shell step keeps its start commit | The run fails with diverged, such as recorded step NAME#0 is a function step, the code asks for a human step |
A recorded step whose input changed returns its recorded value with the warning the input of NAME#N changed since it was recorded; it returned its recorded value.
Definition errors
Section titled “Definition errors”cb.DefinitionError
Section titled “cb.DefinitionError”A pipeline, function step or agent is defined wrong. Its constructors and decorators raise it, and the code server reports it when it loads the factory. A code server whose factory does not load keeps running and logs the error. No run of the factory starts, and its runs in progress wait until the factory loads. Run problems has the fixes.
| Message | Cause |
|---|---|
PATH has no list of strings at [tool.codeband] pipelines |
pyproject.toml lacks the setting, or it is empty or not a list of strings |
reading PATH: ERROR |
pyproject.toml is missing or not valid TOML |
pipelines entry 'ENTRY' is not of the form module:function |
An entry lacks the : or one of its parts |
pipelines entry 'ENTRY': importing MODULE failed: and a traceback |
The module raised on import |
pipelines entry 'ENTRY': module MODULE in FILE has no NAME |
The module lacks the function |
pipelines entry 'ENTRY' is not decorated with @cb.pipeline |
The function lacks the decorator |
pipelines entries 'A' and 'B' both define pipeline 'NAME' |
Two entries name pipelines of the same name |
the factory has no pipeline 'NAME' |
A run asks for a pipeline that the factory does not list |
pipeline NAME declares stage 'STAGE' twice |
The stages list of @cb.pipeline names a stage twice |
pipeline NAME declares VALUE as a stage, want a cb.Stage |
The stages list of @cb.pipeline holds something other than a cb.Stage |
pipeline NAME enters stage 'STAGE' at PATH:LINE, which it does not declare in @cb.pipeline(stages=[...]) |
A with block enters a stage that the stages list of @cb.pipeline does not name, such as a misspelled one |
The module codeband.testing calls a pipeline in a test, without the daemon, the code server or a run. Test a pipeline without a daemon shows the tests of the example pipeline ship_feature.
from codeband.testing import call_pipeline, exitedcodeband.testing.call_pipeline
Section titled “codeband.testing.call_pipeline”def call_pipeline( pipeline: cb.Pipeline[...], run_input: Mapping[str, object] | None = None, *, step_outputs: Mapping[str, Sequence[object]] | None = None, answers: Mapping[str, Sequence[object]] | None = None,) -> PipelineCallCalls the pipeline function once with the arguments of the run input and returns the steps it asked for and how it ended. Each agent step and shell step takes the next step output of its name from step_outputs, and each human step the next answer of its name from answers. Function steps run as plain functions, as they do when a test calls the pipeline itself.
| Parameter | Type | Default | Description |
|---|---|---|---|
pipeline |
cb.Pipeline |
required | The pipeline, made with @cb.pipeline |
run_input |
Mapping[str, object] | None |
None |
The run input: the argument of each parameter of the pipeline, by parameter name, such as {"problem": "README.md says Helo"}. Each argument is checked against its parameter’s type as in a run, so it can also be JSON. None for a pipeline without parameters |
step_outputs |
Mapping[str, Sequence[object]] | None |
None |
By agent name or shell step name, the step output of each of its steps, in order |
answers |
Mapping[str, Sequence[object]] | None |
None |
By human step name, the answer to each of its human steps, in order |
cb.start_commit() returns codeband.testing.START_COMMIT, a fixed commit ID.
What a step gets in the test:
| Step | Gives the test | Pipeline code gets |
|---|---|---|
| Agent step | A value of the agent’s output type, or the same as JSON, such as {"questions": [...]} for a cb.MayAsk output that asks |
A cb.AgentStep with the output. Its commit is a commit ID made from the step ID for an agent with access="write", which moves the run head there, and the agent step’s start commit for access="read" |
| Agent step | A cb.FakeFailure |
cb.AgentStepFailedError with the failure’s kind and message |
Parallel agent step of start() |
The same as an agent step, which it takes when it starts | From cb.gather(), the cb.AgentSteps in argument order, or the cb.AgentStepFailedError of the first failed one in argument order. The run head stays where it is |
| Shell step | A cb.ShellStep, for example from exited |
The cb.ShellStep |
| Human step | A value of the answer type, or the same as JSON |
The answer, checked against the answer type as a person’s answer is |
| Function step | Nothing | The function’s return value, or its own exception |
An agent step renders the agent’s prompt with its input, so a prompt that does not render fails the test as it fails a run. A stage block that the pipeline does not declare, a stage block inside a stage block, and one name for two kinds of steps raise cb.DefinitionError. cb.Stop ends the call with stop_reason; any other exception from the pipeline reaches the test. A run input that misses a required parameter, names an unknown one or has a value of the wrong type raises pydantic’s ValidationError, and a pipeline that returns neither a cb.RunResult nor None raises TypeError, as they fail a run.
call_pipeline checks what the pipeline does for its run input and step outputs. It runs no program and no agent, and it does not replay the pipeline, so it does not check the rules of run replay or timeouts.
PipelineCall and Step
Section titled “PipelineCall and Step”@dataclass(frozen=True)class PipelineCall: steps: tuple[Step, ...] code_change: cb.CodeChange | None tickets: tuple[cb.NewTicket, ...] stop_reason: str | None
@dataclass(frozen=True)class Step: id: str kind: Literal["agent_step", "function_step", "shell_step", "human_step"] stage: str input: Any output: AnyPipelineCall holds every step that the pipeline asked for, in order, and how the call ended: code_change is the code change of the cb.RunResult that the pipeline returned, None when the run result has none or the pipeline returned None or stopped, tickets holds the new tickets of the run result, empty when the pipeline returned None or stopped, and stop_reason is the reason of its cb.Stop, None when it returned.
Step field |
Value |
|---|---|
id |
The step ID, such as builder#0, counted per name as in a run |
kind |
The kind of step |
stage |
The name of the stage block that the step started in, or empty outside one |
input |
The agent input of an agent step, the question of a human step, the argv list of a shell step, or the arguments of a function step by parameter name |
output |
What pipeline code got: the cb.AgentStep, the cb.ShellStep, the answer, or the function step’s value. None when the step raised |
codeband.testing.exited
Section titled “codeband.testing.exited”def exited(exit_code: int, output: str = "") -> cb.ShellStepReturns the step output of a shell step whose program exited with exit_code and wrote output: ok is true for exit code 0, and the program did not time out or change files. Build a cb.ShellStep for a timeout.
codeband.testing.StepOutputError
Section titled “codeband.testing.StepOutputError”The step outputs and answers of the test don’t fit the steps that the pipeline asked for: a step has no step output or answer left, a step output or answer does not fit its type, or some are left over when the pipeline ends. The message names the step ID, such as the pipeline asks for builder#0, but the test gives no step output for it. StepOutputError is a BaseException, so except Exception in pipeline code lets it through to the test.
[tool.codeband] settings
Section titled “[tool.codeband] settings”The pyproject.toml of a factory holds the codeband settings under [tool.codeband].
| Key | Type | Required | Description |
|---|---|---|---|
pipelines |
list of strings | Yes | The pipelines of the factory, each as module:function. The module is imported from the factory folder; the function is decorated with @cb.pipeline |
scorers |
list of strings | No | The scorers of the factory, each as module:function. The function is decorated with @cb.scorer |
[tool.codeband]pipelines = ["py_factory.pipeline:intake", "py_factory.program:run_program"]The code server puts the factory folder first on Python’s import path, then imports each module. Every function step and agent that those imports define belongs to the factory. The code server also tells the daemon the source’s folder, its git commit and whether it has uncommitted changes.
codeband-codeserver
Section titled “codeband-codeserver”usage: codeband-codeserver [-h] [--address ADDRESS] [--stateDir STATE_DIR]The code server of the Python SDK. The SDK installs it in the Python environment of the factory, and codeband codeserver runs it with every argument you give. Start it in the factory folder:
uv run codeband codeservercodeband dev starts it together with the daemon, in one terminal.
It loads the factory in its working folder once, then runs pipeline code and function steps when the daemon asks. It does not see code that changes after it starts: to load changed code, start it again. codeband dev starts it again each time a file of the factory changes. It runs until SIGINT or SIGTERM.
| Flag | Environment variable | Default | Description |
|---|---|---|---|
--address |
unix:STATE/codeserver.sock |
unix:PATH or http://HOST:PORT to listen on. STATE is the state folder |
|
--stateDir |
CODEBAND_STATE_DIR |
$XDG_STATE_HOME/codeband, or ~/.local/state/codeband when XDG_STATE_HOME is not set |
The state folder shared with the daemon |
CODEBAND_LOG_LEVEL |
info |
Lowest level that is logged: debug, info, warn or error |
On a Unix socket, only your user can connect, because whoever connects runs function steps. The code server removes its socket file when it stops on SIGINT or SIGTERM. A code server that was killed leaves the file behind, and the next start removes a socket file that no process listens on. The code server exits when another process listens on the path, with codeband-codeserver: another process listens on PATH. An address of another form exits with codeband-codeserver: address 'ADDRESS' is neither unix:PATH nor http://HOST:PORT. codeband daemon reaches the code server at the address that the code_server field of its [factories.NAME] table in codeband.toml names, so give each code server of a daemon its own address.
The code server writes each log record to standard error as one JSON object on one line. codeband codeserver and codeband dev read these lines and write the records in the format of codeband --log.format, and they set CODEBAND_LOG_LEVEL from codeband --log.level. Run without them, as codeband-codeserver, the code server writes the JSON lines. On start, it names the pipelines it loaded, and then logs Serving pipelines with its address once it answers requests:
{"time":"2026-11-24T12:48:12.150375+01:00","level":"INFO","msg":"Loaded pipelines","pipelines":["intake","run_program"],"folder":"/home/you/codeband/examples/py-factory"}{"time":"2026-11-24T12:48:12.179842+01:00","level":"INFO","msg":"Serving pipelines","address":"unix:/home/you/.local/state/codeband/codeserver.sock"}A factory that does not load gives an error record in place of the first one:
{"time":"2026-11-24T12:48:19.970500+01:00","level":"ERROR","msg":"The factory does not load","folder":"/home/you/fixes","err":"/home/you/fixes/pyproject.toml has no list of strings at [tool.codeband] pipelines"}The records of Python’s logging module in your pipeline code reach the same log. A record of a logger outside codeband names that logger in logger, every extra= value becomes a key of its own, and an exception gives err with its one-line text and stack with the traceback. The code server logs each request it gets at debug.
Next steps
Section titled “Next steps”- Quickstart: run the example pipeline
intakewith the code server and the daemon. - Architecture: see where the code server runs and how it finds the daemon.
- codeband CLI: look up
codeband run,codeband answerand the daemon’s flags. - Run problems: fix a run that fails with
definition_errorordiverged.