Cancel

Turn with a canceled context.Context on the one SDK, pkg/abox.

Requires protocol 4 (Capabilities().Cancel is true after Open). A 3s turn deadline fires cancel_turn. In-flight run_command is killed.

CLI

There is no --timeout flag. Ctrl+C (SIGINT) cancels an in-flight turn (protocol 4), including guest run_command:

abox exec --prompt "Count slowly from 1 to 50 in words."
# Ctrl+C → cancel_turn

In the TUI, Ctrl+C quits (and denies an in-flight approval first). On Linux, top-level SIGTERM and SIGHUP also cancel and return through bounded VM cleanup; the Linux helper fallback is SIGTERM. macOS retains its interrupt fallback. MaxTurns and a turn Timeout are SDK-only (Turn options).

SDK

package main

import (
	"context"
	"fmt"
	"os"
	"time"

	"github.com/AdminTurnedDevOps/ABox/pkg/abox"
)

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 8*time.Second)
	defer cancel()
	sess, err := abox.Open(ctx, abox.Options{BootTimeout: 60 * time.Second})
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	defer sess.Close()
	if !sess.Capabilities().Cancel {
		fmt.Fprintln(os.Stderr, "guest cannot cancel (protocol", sess.Capabilities().Protocol, ")")
		os.Exit(1)
	}
	turnCtx, stop := context.WithTimeout(ctx, 3*time.Second)
	defer stop()
	res, err := sess.Turn(turnCtx, "Count slowly from 1 to 50 in words.", func(ev abox.Event) {
		if ev.Kind == "text" {
			fmt.Print(ev.Text)
		}
	})
	fmt.Println()
	if res != nil {
		fmt.Println("canceled", res.Canceled)
	}
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
	}
}