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, andbunInstallinstall packages.copyandcopyItemsadd local files.runCmdexecutes one command or a sequence of commands.setUserandsetWorkdirchange the context for following instructions.makeDir,remove,rename, andmakeSymlinkmanage files.gitCloneclones 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.