Skip to main content

Install packages

from nullspace import Template

builder = (
    Template()
    .from_ubuntu_image("22.04")
    .apt_install(["git", "curl", "ripgrep"])
    .pip_install(["requests", "pytest"])
    .npm_install(["typescript"], g=True)
    .bun_install(["vite"], g=True)
)
Common base-image helpers include from_ubuntu_image(), from_python_image(), from_bun_image(), from_dockerfile(), and from_dockerfile_content(). Package installers accept lists. For npm_install() and bun_install(), g=True performs a global install.

Files, repos, and commands

builder = (
    Template()
    .from_python_image("3.12")
    .copy("./app.py", "/workspace/app.py")
    .copy_items([("./pyproject.toml", "/workspace/pyproject.toml")])
    .git_clone("https://github.com/pypa/sampleproject.git", "/workspace/sampleproject")
    .run_cmd("python3 -m compileall /workspace")
)
Use set_file_context() when a build needs a local context directory for copy steps. Use registry-auth helpers before pulling private images.

Environment, user, and workdir

builder = (
    builder
    .set_build_envs({"PIP_INDEX_URL": "https://example.invalid/simple"})
    .set_runtime_envs({"APP_ENV": "production"})
    .set_workdir("/workspace")
    .set_user("user")
)
Build envs are visible only during build steps. Runtime envs are persisted into sandboxes launched from the template.

File operations

builder = (
    builder
    .make_dir("/workspace/logs")
    .make_symlink("/workspace/app.py", "/usr/local/bin/app.py")
    .rename("/workspace/app.py", "/workspace/main.py")
    .remove("/tmp/cache", recursive=True, force=True)
)

Render before build

print(builder.to_json())
print(builder.to_dockerfile())
Rendered templates are useful for review, CI diffs, and nullspace template render json|dockerfile parity. Build resource and cache options live on the build call:
build = Template.build(
    builder,
    name="agent-template",
    tags=["stable"],
    cpu_count=4,
    memory_mb=2048,
    skip_cache=True,
)
The same options are available on Template.build_in_background() and builder.to_json(...).