docs/versioned_docs/version-1.0-beta/extending/how-dagger-works/functions.mdx
A function is something a caller can run.
It is the main way a module shows its value. Functions accept typed inputs and return typed outputs. They can be called from the CLI, from another module, from a generated client, or by a check.
A function is not a shell step with a name. It is part of an API.
Good functions sound like what the user wants:
Do not expose every internal step. Expose the action the user cares about.
Inputs should be visible and typed.
Use:
Directory or File for source and artifactsSecret for credentialsService for network dependenciesAvoid:
Return the richest useful value.
Container if the caller may keep building or publish it.Directory or File for artifacts.Changeset for proposed edits.Do not flatten everything into logs or strings. Typed outputs are how modules compose.
Not every function belongs at the top level.
Use an object when a concept has state:
Objects make multi-step workflows feel natural without hiding data.
Calling a function often describes work. The engine runs the work when a result is needed.
This is why return types matter. A function that returns a Container lets the caller keep building. A function that reads a string forces work to finish.
Next: Checks.