Skip to content

Template definition

Template() creates a builder. Every call appends an instruction and returns the same builder, so you can express the build as a chain.

This example starts from Ubuntu. AgentBox installs Python, sets a working directory, copies a file, and starts an HTTP server. The ready command completes the build only after the file is available over HTTP.

mjs
import { Sandbox, Template, waitForURL } from "@abox-dev/sdk";

const templateName = process.env.TEMPLATE_NAME ?? "python-service";

const template = Template({ fileContextPath: "." })
  .fromUbuntuImage("24.04")
  .aptInstall("python3")
  .setWorkdir("/home/user/app")
  .copy("message.txt", "/home/user/app/message.txt")
  .setStartCmd(
    "python3 -m http.server 8080",
    waitForURL("http://localhost:8080/message.txt"),
  );

await Template.build(template, templateName);

const sandbox = await Sandbox.create(templateName);
try {
  const result = await sandbox.commands.run(
    "whoami && pwd && curl --silent http://localhost:8080/message.txt",
  );
  console.log(result.stdout);
} finally {
  await sandbox.kill();
}

Common instructions

  • aptInstall, pipInstall, npmInstall, and bunInstall install packages.
  • copy and copyItems add local files.
  • runCmd executes one command or a sequence of commands.
  • setUser and setWorkdir change the context for following instructions.
  • makeDir, remove, rename, and makeSymlink manage files.
  • gitClone clones a repository during the build.

Variables from setEnvs are available only during the build. Set runtime variables when you create the sandbox.

See the SDK reference for every builder method.