Templates capture setup once so every machine can start from a ready environment.
from nullspace import Machine, Template, default_build_logger
builder = (
Template()
.from_python_image("3.12")
.apt_install(["git", "curl"])
.pip_install(["fastapi", "uvicorn"])
.copy("./app.py", "/workspace/app.py")
.set_workdir("/workspace")
)
build = Template.build(
builder,
name="fastapi-agent",
tags=["stable"],
on_log_entry=default_build_logger(),
)
with Machine.create(template=build.canonical_ref) as machine:
result = machine.commands.run("python3 --version", shell=True)
print(result.stdout)
Use Template.build_in_background() when a build should continue while your
client disconnects or polls progress later.
build = Template.build_in_background(builder, name="fastapi-agent", tags=["next"])
finished = build.wait_until_terminal()
print(finished.build.status)
The TypeScript SDK builds synchronously over the SSE stream; for
background builds and polling, use the Python SDK, CLI, or HTTP API.
See the API reference for the full template build request
schema and background-build polling.