Tags and versions
A tag points to a specific build. A complete reference uses name:tag, for example python-tools:v1 or python-tools:production.
Pass one or more tags to Template.build. You can then assign and remove tags without rebuilding the template.
mjs
import { Sandbox, Template } from "@abox-dev/sdk";
const templateName = process.env.TEMPLATE_NAME ?? "versioned-template";
const template = Template().fromBaseImage().runCmd("echo versioned");
await Template.build(template, templateName, {
tags: ["v1", "stable"],
});
await Template.assignTags(`${templateName}:v1`, "production");
await Template.removeTags(templateName, "stable");
const tags = await Template.getTags(templateName);
console.log(
tags
.map(({ tag }) => tag)
.sort()
.join(", "),
);
const sandbox = await Sandbox.create(`${templateName}:production`);
try {
console.log(`Started ${sandbox.sandboxId}`);
} finally {
await sandbox.kill();
}py
import os
from agentbox import Sandbox, Template
template_name = os.getenv("TEMPLATE_NAME", "versioned-template")
template = Template().from_base_image().run_cmd("echo versioned")
Template.build(template, template_name, tags=["v1", "stable"])
Template.assign_tags(f"{template_name}:v1", "production")
Template.remove_tags(template_name, "stable")
tags = Template.get_tags(template_name)
print(", ".join(sorted(tag.tag for tag in tags)))
sandbox = Sandbox.create(f"{template_name}:production")
try:
print(f"Started {sandbox.sandbox_id}")
finally:
sandbox.kill()go
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/abox-dev/sdk/packages/go-sdk"
)
func kill(sandbox *agentbox.Sandbox) {
if _, err := sandbox.Kill(context.Background()); err != nil {
log.Printf("cleanup sandbox: %v", err)
}
}
func run() (err error) {
ctx := context.Background()
client, err := agentbox.NewClient()
if err != nil {
return err
}
name := os.Getenv("TEMPLATE_NAME")
if name == "" {
name = "versioned-template"
}
builder := agentbox.NewTemplate("").
FromBase().
Run("echo versioned")
if _, err := client.Templates.Build(ctx, builder, name, &agentbox.TemplateBuildOptions{
Tags: []string{"v1", "stable"},
}); err != nil {
return err
}
if _, err := client.Templates.AssignTags(ctx, name+":v1", []string{"production"}); err != nil {
return err
}
if err := client.Templates.RemoveTags(ctx, name, []string{"stable"}); err != nil {
return err
}
value1, err := client.Templates.Tags(ctx, name)
if err != nil {
return err
}
for _, tag := range value1 {
fmt.Println(tag.Tag)
}
sandbox, err := client.Sandboxes.Create(ctx, &agentbox.CreateSandboxOptions{Template: name + ":production"})
if err != nil {
return err
}
defer kill(sandbox)
fmt.Println("Started", sandbox.ID)
return nil
}
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}assignTags or assign_tags moves a new tag to the selected build. removeTags or remove_tags removes only that pointer; other tags for the build keep working. getTags or get_tags returns the tag, build ID, and assignment time.
Use tags such as v1.4.0 for immutable releases and staging or production for promotion. Starting a sandbox from an explicit tag makes the selected version clear.