@madarco/agentbox 0.19.0 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +83 -0
- package/dist/{_cloud-attach-YM2KOWHO.js → _cloud-attach-MH7NKIZY.js} +7 -5
- package/dist/{chunk-SPUUOEW2.js → chunk-3465NDRZ.js} +98 -9
- package/dist/chunk-3465NDRZ.js.map +1 -0
- package/dist/{chunk-JK5V4OLT.js → chunk-4ATVA3RM.js} +194 -34
- package/dist/chunk-4ATVA3RM.js.map +1 -0
- package/dist/{chunk-Y6PUCLOE.js → chunk-52LKNUY7.js} +5 -2
- package/dist/chunk-52LKNUY7.js.map +1 -0
- package/dist/{chunk-A5OFRJDI.js → chunk-5N7GA2X7.js} +133 -97
- package/dist/chunk-5N7GA2X7.js.map +1 -0
- package/dist/{dist-EKSNZHDY.js → dist-AJWL4WLW.js} +8 -2
- package/dist/{dist-VQSZVBT3.js → dist-CTTTHG6U.js} +5 -4
- package/dist/{dist-VQSZVBT3.js.map → dist-CTTTHG6U.js.map} +1 -1
- package/dist/{dist-U2BHTWG4.js → dist-G5PDFWKH.js} +10 -6
- package/dist/dist-G5PDFWKH.js.map +1 -0
- package/dist/{dist-FTCDWRAL.js → dist-LUEH7MER.js} +3 -3
- package/dist/dist-LUEH7MER.js.map +1 -0
- package/dist/{dist-PRDYMXCX.js → dist-T3JIYHCA.js} +3 -3
- package/dist/index.js +789 -291
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/runtime/docker/Dockerfile.box +13 -0
- package/runtime/docker/packages/ctl/dist/bin.cjs +122 -62
- package/runtime/docker/packages/sandbox-docker/scripts/claude-managed-settings.json +4 -4
- package/runtime/e2b/agentbox-dockerd-start +145 -0
- package/runtime/e2b/attach-helper.cjs +27 -3
- package/runtime/e2b/claude-managed-settings.json +4 -4
- package/runtime/e2b/ctl.cjs +122 -62
- package/runtime/e2b/scripts/build-template.sh +32 -5
- package/runtime/hetzner/claude-managed-settings.json +4 -4
- package/runtime/hetzner/ctl.cjs +122 -62
- package/runtime/hetzner/scripts/install-box.sh +9 -0
- package/runtime/relay/bin.cjs +6 -0
- package/runtime/vercel/claude-managed-settings.json +4 -4
- package/runtime/vercel/ctl.cjs +122 -62
- package/runtime/vercel/scripts/provision.sh +20 -0
- package/share/host-skills/agentbox/SKILL.md +2 -2
- package/share/host-skills/agentbox-info/SKILL.md +6 -6
- package/share/host-skills/codex/agentbox.md +2 -2
- package/share/host-skills/opencode/agentbox.md +2 -2
- package/dist/chunk-A5OFRJDI.js.map +0 -1
- package/dist/chunk-JK5V4OLT.js.map +0 -1
- package/dist/chunk-SPUUOEW2.js.map +0 -1
- package/dist/chunk-Y6PUCLOE.js.map +0 -1
- package/dist/dist-FTCDWRAL.js.map +0 -1
- package/dist/dist-U2BHTWG4.js.map +0 -1
- /package/dist/{_cloud-attach-YM2KOWHO.js.map → _cloud-attach-MH7NKIZY.js.map} +0 -0
- /package/dist/{dist-EKSNZHDY.js.map → dist-AJWL4WLW.js.map} +0 -0
- /package/dist/{dist-PRDYMXCX.js.map → dist-T3JIYHCA.js.map} +0 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Start the in-box dockerd. Launched by the host via
|
|
3
|
+
# `docker exec -d --user root`. Idempotent — safe to call again on
|
|
4
|
+
# `agentbox start`. The storage driver is selected at runtime (see
|
|
5
|
+
# select_storage_driver below): the kernel-native `overlay2` when a probe
|
|
6
|
+
# proves it works on the data-root filesystem, otherwise `fuse-overlayfs`.
|
|
7
|
+
# The chosen driver is written to /etc/docker/daemon.json before launch.
|
|
8
|
+
|
|
9
|
+
set -euo pipefail
|
|
10
|
+
|
|
11
|
+
if pgrep -x dockerd >/dev/null; then
|
|
12
|
+
# dockerd already up — but a prior run may have died after the daemon became
|
|
13
|
+
# ready yet before it widened the socket, leaving it 0660 and unreachable by
|
|
14
|
+
# the unprivileged box user. Re-assert the chmod (see the note on the
|
|
15
|
+
# fresh-start path below) before the idempotent early exit.
|
|
16
|
+
chmod 666 /var/run/docker.sock 2>/dev/null || true
|
|
17
|
+
exit 0
|
|
18
|
+
fi
|
|
19
|
+
|
|
20
|
+
mkdir -p /var/lib/docker /var/run /var/log/agentbox
|
|
21
|
+
|
|
22
|
+
# /var/run lives in the container's writable layer (not a volume), so files
|
|
23
|
+
# written by the previous dockerd run survive `docker stop`/`start`. dockerd
|
|
24
|
+
# refuses to start if `/var/run/docker.pid` exists with a PID in /proc — and
|
|
25
|
+
# after restart, that PID number has been reassigned to (probably) the new
|
|
26
|
+
# `sleep infinity`. Wipe both the pidfile and the stale socket here; pgrep
|
|
27
|
+
# above already confirmed no real dockerd is running.
|
|
28
|
+
rm -f /var/run/docker.pid /var/run/docker.sock
|
|
29
|
+
|
|
30
|
+
# Cgroup v2 + unprivileged DinD on OrbStack/Docker Desktop: the outer
|
|
31
|
+
# container has /sys/fs/cgroup and /proc/sys bind-mounted RO from the host
|
|
32
|
+
# (Docker's standard hardening). We need both writable for dockerd to:
|
|
33
|
+
# * mkdir /sys/fs/cgroup/docker (its own cgroup slice for child containers)
|
|
34
|
+
# * write /proc/sys/net/ipv6/conf/<veth>/disable_ipv6 (default bridge setup)
|
|
35
|
+
# Without these, `docker run` fails with EROFS or "failed to disable IPv6".
|
|
36
|
+
# SYS_ADMIN + the private cgroup namespace let us remount these RW; the
|
|
37
|
+
# writes only affect the box's own namespaces (not the host). Failure is
|
|
38
|
+
# tolerable — some hosts already mount these RW.
|
|
39
|
+
mount -o remount,rw /sys/fs/cgroup 2>/dev/null || true
|
|
40
|
+
mount -o remount,rw /proc/sys 2>/dev/null || true
|
|
41
|
+
|
|
42
|
+
# --- Storage-driver selection -------------------------------------------------
|
|
43
|
+
# The inner dockerd's data root (/var/lib/docker, a Docker named volume) used
|
|
44
|
+
# to be pinned to fuse-overlayfs. fuse-overlayfs is broken on recent kernels
|
|
45
|
+
# (e.g. Docker Desktop's 6.x linuxkit kernel): inner `docker run` fails at
|
|
46
|
+
# execve() with "exec ...: invalid argument". The kernel-native overlay2
|
|
47
|
+
# driver works when the data-root filesystem can carry an overlay mount, which
|
|
48
|
+
# the ext4 named volume can. We pick overlay2 when a probe proves it works,
|
|
49
|
+
# else fall back to fuse-overlayfs.
|
|
50
|
+
#
|
|
51
|
+
# dockerd refuses to switch drivers once its data root is populated, so if the
|
|
52
|
+
# data root is already initialized under one driver we reuse that driver and
|
|
53
|
+
# skip the probe — a box created under one driver never switches.
|
|
54
|
+
DOCKER_DATA_ROOT=/var/lib/docker
|
|
55
|
+
DAEMON_JSON=/etc/docker/daemon.json
|
|
56
|
+
|
|
57
|
+
probe_overlay2() {
|
|
58
|
+
# The kernel overlay filesystem has to exist at all.
|
|
59
|
+
grep -qw overlay /proc/filesystems 2>/dev/null || return 1
|
|
60
|
+
|
|
61
|
+
local probe lower upper work merged ok=1
|
|
62
|
+
# The probe dir MUST live inside the data root so the test overlay is mounted
|
|
63
|
+
# on the SAME filesystem the real graph will use. A probe under /tmp would
|
|
64
|
+
# test the container's overlayfs writable layer — the wrong filesystem.
|
|
65
|
+
probe="$(mktemp -d "$DOCKER_DATA_ROOT/.overlay2-probe.XXXXXX" 2>/dev/null)" || return 1
|
|
66
|
+
lower="$probe/lower"; upper="$probe/upper"; work="$probe/work"; merged="$probe/merged"
|
|
67
|
+
mkdir -p "$lower" "$upper" "$work" "$merged" || { rm -rf "$probe"; return 1; }
|
|
68
|
+
|
|
69
|
+
# Stage a known-good executable so the merged view exposes it.
|
|
70
|
+
cp /bin/true "$lower/probe-bin" 2>/dev/null || { rm -rf "$probe"; return 1; }
|
|
71
|
+
chmod 0755 "$lower/probe-bin" 2>/dev/null || true
|
|
72
|
+
|
|
73
|
+
if mount -t overlay overlay \
|
|
74
|
+
-o "lowerdir=$lower,upperdir=$upper,workdir=$work" "$merged" 2>/dev/null; then
|
|
75
|
+
# The actual fuse-overlayfs failure mode: execve from the merged dir. A
|
|
76
|
+
# successful mount is not enough — fuse-overlayfs mounts fine and only
|
|
77
|
+
# fails here.
|
|
78
|
+
"$merged/probe-bin" >/dev/null 2>&1 || ok=0
|
|
79
|
+
umount "$merged" 2>/dev/null || umount -l "$merged" 2>/dev/null || true
|
|
80
|
+
else
|
|
81
|
+
ok=0
|
|
82
|
+
fi
|
|
83
|
+
rm -rf "$probe"
|
|
84
|
+
[ "$ok" = 1 ]
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
select_storage_driver() {
|
|
88
|
+
# 1. Reuse an already-initialized data root's driver — dockerd cannot switch
|
|
89
|
+
# a populated data root, and this script reruns on every `agentbox start`.
|
|
90
|
+
local has_overlay2=0 has_fuse=0
|
|
91
|
+
[ -d "$DOCKER_DATA_ROOT/overlay2" ] \
|
|
92
|
+
&& [ -n "$(ls -A "$DOCKER_DATA_ROOT/overlay2" 2>/dev/null)" ] && has_overlay2=1
|
|
93
|
+
[ -d "$DOCKER_DATA_ROOT/fuse-overlayfs" ] \
|
|
94
|
+
&& [ -n "$(ls -A "$DOCKER_DATA_ROOT/fuse-overlayfs" 2>/dev/null)" ] && has_fuse=1
|
|
95
|
+
if [ "$has_overlay2" = 1 ]; then echo "overlay2"; return 0; fi
|
|
96
|
+
if [ "$has_fuse" = 1 ]; then echo "fuse-overlayfs"; return 0; fi
|
|
97
|
+
|
|
98
|
+
# 2. Fresh data root: probe overlay2 against the data-root filesystem.
|
|
99
|
+
if probe_overlay2; then echo "overlay2"; return 0; fi
|
|
100
|
+
echo "fuse-overlayfs"
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
# Sweep any leaked probe dir from a hard-killed previous run (cosmetic; the
|
|
104
|
+
# driver subdir checks above ignore it, and dockerd ignores non-driver dirs).
|
|
105
|
+
rm -rf "$DOCKER_DATA_ROOT"/.overlay2-probe.* 2>/dev/null || true
|
|
106
|
+
|
|
107
|
+
STORAGE_DRIVER="$(select_storage_driver)"
|
|
108
|
+
|
|
109
|
+
# Write daemon.json with the resolved driver. `iptables: true` stays for inner
|
|
110
|
+
# bridge networking. Rewritten every start, but the driver is stable (step 1
|
|
111
|
+
# above), so this never causes a mid-life driver switch.
|
|
112
|
+
mkdir -p /etc/docker
|
|
113
|
+
printf '%s\n' \
|
|
114
|
+
"{ \"storage-driver\": \"$STORAGE_DRIVER\", \"iptables\": true }" \
|
|
115
|
+
> "$DAEMON_JSON"
|
|
116
|
+
# Truncate dockerd.log fresh for this start, marker line first; dockerd appends.
|
|
117
|
+
echo "agentbox-dockerd-start: storage-driver=$STORAGE_DRIVER" \
|
|
118
|
+
> /var/log/agentbox/dockerd.log
|
|
119
|
+
# --- end storage-driver selection --------------------------------------------
|
|
120
|
+
|
|
121
|
+
# nohup + & + disown lets us survive the `docker exec -d` returning. dockerd
|
|
122
|
+
# reads /etc/docker/daemon.json on its own; no flags here keeps the start path
|
|
123
|
+
# debuggable from inside the container (just edit the file and restart).
|
|
124
|
+
nohup dockerd >>/var/log/agentbox/dockerd.log 2>&1 &
|
|
125
|
+
|
|
126
|
+
# Wait for the socket to become accept()-able. Bound by ~30s — first start has
|
|
127
|
+
# to initialize iptables chains and the storage graphdriver (fuse-overlayfs is
|
|
128
|
+
# noticeably slower to initialize than overlay2).
|
|
129
|
+
for _ in $(seq 1 300); do
|
|
130
|
+
if [ -S /var/run/docker.sock ] \
|
|
131
|
+
&& docker -H unix:///var/run/docker.sock info >/dev/null 2>&1; then
|
|
132
|
+
break
|
|
133
|
+
fi
|
|
134
|
+
sleep 0.1
|
|
135
|
+
done
|
|
136
|
+
|
|
137
|
+
# Open the socket to the unprivileged box user. dockerd creates it root:docker
|
|
138
|
+
# 0660; the in-box agent and the ctl supervisor's `image:` services run as the
|
|
139
|
+
# box user, whose already-running session may not carry the docker group, so
|
|
140
|
+
# widen to 0666. Single-tenant box, so this is safe; correctly timed here (run
|
|
141
|
+
# as root, right after the socket is ready) so the cloud launcher's poll — which
|
|
142
|
+
# runs `docker info` as the box user — can succeed.
|
|
143
|
+
chmod 666 /var/run/docker.sock 2>/dev/null || true
|
|
144
|
+
|
|
145
|
+
disown -a
|
|
@@ -53,6 +53,7 @@ function parseEnvFile(body) {
|
|
|
53
53
|
function parseArgs(argv) {
|
|
54
54
|
let sandboxId;
|
|
55
55
|
let user = "vscode";
|
|
56
|
+
let detached = false;
|
|
56
57
|
for (let i = 0; i < argv.length; i++) {
|
|
57
58
|
const a = argv[i];
|
|
58
59
|
if (a === "--sandbox-id") {
|
|
@@ -61,16 +62,18 @@ function parseArgs(argv) {
|
|
|
61
62
|
} else if (a === "--user") {
|
|
62
63
|
user = argv[i + 1] ?? user;
|
|
63
64
|
i++;
|
|
65
|
+
} else if (a === "--detached") {
|
|
66
|
+
detached = true;
|
|
64
67
|
}
|
|
65
68
|
}
|
|
66
69
|
if (!sandboxId) {
|
|
67
70
|
process.stderr.write("attach-helper: --sandbox-id is required\n");
|
|
68
71
|
process.exit(2);
|
|
69
72
|
}
|
|
70
|
-
return { sandboxId, user };
|
|
73
|
+
return { sandboxId, user, detached };
|
|
71
74
|
}
|
|
72
75
|
async function main() {
|
|
73
|
-
const { sandboxId, user } = parseArgs(process.argv.slice(2));
|
|
76
|
+
const { sandboxId, user, detached } = parseArgs(process.argv.slice(2));
|
|
74
77
|
ensureE2bEnvLoaded();
|
|
75
78
|
const inner = process.env.AGENTBOX_E2B_INNER_CMD;
|
|
76
79
|
if (!inner) {
|
|
@@ -92,6 +95,24 @@ async function main() {
|
|
|
92
95
|
);
|
|
93
96
|
process.exit(1);
|
|
94
97
|
}
|
|
98
|
+
if (detached) {
|
|
99
|
+
try {
|
|
100
|
+
const r = await sb.commands.run(inner, {
|
|
101
|
+
user,
|
|
102
|
+
cwd: "/workspace",
|
|
103
|
+
timeoutMs: 5 * 6e4
|
|
104
|
+
});
|
|
105
|
+
process.exit(r.exitCode ?? 0);
|
|
106
|
+
} catch (err) {
|
|
107
|
+
const code = err.exitCode;
|
|
108
|
+
if (typeof code === "number") process.exit(code);
|
|
109
|
+
process.stderr.write(
|
|
110
|
+
`attach-helper: detached pre-start failed: ${err instanceof Error ? err.message : String(err)}
|
|
111
|
+
`
|
|
112
|
+
);
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
95
116
|
const cols = process.stdout.columns && process.stdout.columns > 0 ? process.stdout.columns : 80;
|
|
96
117
|
const rows = process.stdout.rows && process.stdout.rows > 0 ? process.stdout.rows : 24;
|
|
97
118
|
if (process.stdin.isTTY && typeof process.stdin.setRawMode === "function") {
|
|
@@ -106,7 +127,10 @@ async function main() {
|
|
|
106
127
|
envs: {
|
|
107
128
|
LANG: "C.UTF-8",
|
|
108
129
|
LC_ALL: "C.UTF-8",
|
|
109
|
-
|
|
130
|
+
// Forwarded from the host by build-attach.ts. The inner command's TERM
|
|
131
|
+
// guard (renderInnerCommand) downgrades to xterm-256color when the box's
|
|
132
|
+
// terminfo lacks it, so an exotic host TERM never breaks the attach.
|
|
133
|
+
TERM: process.env.AGENTBOX_HOST_TERM || "xterm-256color"
|
|
110
134
|
},
|
|
111
135
|
// Long-lived. We don't want the SDK reaping the PTY mid-session.
|
|
112
136
|
timeoutMs: 55 * 6e4,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$comment": "AgentBox enterprise-managed Claude Code settings, baked into the box image at /etc/claude-code/managed-settings.json. Highest precedence and NOT synced from the host ~/.claude, so claude-hooks-filter.ts never touches it; per Claude Code, hook arrays MERGE across settings sources, so the user's own hooks still run. These hooks report Claude's activity to the box supervisor (agentbox-ctl claude-state -> ctl socket -> relay -> ~/.agentbox/boxes/<id>/status.json) so `agentbox status/list/inspect` can show it even when the box is paused. Each command is exit-0 fast and shell-backgrounded so a hook can never block or fail a Claude turn. The ExitPlanMode / AskUserQuestion entries run SYNCHRONOUSLY (no &) because they consume the hook's stdin payload; the catchall PreToolUse 'working' hook races with them, but the supervisor's sticky-state semantics swallow that race (a 'working' set while in end-plan/question is ignored unless --clear-pending is set, which only the matching PostToolUse hook passes). skipDangerousModePermissionPrompt pre-accepts the bypass-permissions disclaimer at policy precedence — AgentBox boxes are isolated, and `agentbox claude` defaults to --dangerously-skip-permissions, so the one-time accept gate would just trap every fresh box.",
|
|
2
|
+
"$comment": "AgentBox enterprise-managed Claude Code settings, baked into the box image at /etc/claude-code/managed-settings.json. Highest precedence and NOT synced from the host ~/.claude, so claude-hooks-filter.ts never touches it; per Claude Code, hook arrays MERGE across settings sources, so the user's own hooks still run. These hooks report Claude's activity to the box supervisor (agentbox-ctl claude-state -> ctl socket -> relay -> ~/.agentbox/boxes/<id>/status.json) so `agentbox status/list/inspect` can show it even when the box is paused. Each command is exit-0 fast and shell-backgrounded so a hook can never block or fail a Claude turn. The ExitPlanMode / AskUserQuestion entries run SYNCHRONOUSLY (no &) because they consume the hook's stdin payload; the catchall PreToolUse 'working' hook races with them, but the supervisor's sticky-state semantics swallow that race (a 'working' set while in end-plan/question is ignored unless --clear-pending is set, which only the matching PostToolUse hook passes). The SessionStart / Stop entries also run SYNCHRONOUSLY (no &) with --capture-session: they read the hook's stdin session_id and record it to the box's per-box session pointer (~/.local/state/agentbox/claude-session) so a box restart can resume the exact conversation (claude --resume <id>); they fire often enough to track /new and /branch, which mint fresh session ids. (A backgrounded `&` hook would detach stdin, so capture hooks must be synchronous.) skipDangerousModePermissionPrompt pre-accepts the bypass-permissions disclaimer at policy precedence — AgentBox boxes are isolated, and `agentbox claude` defaults to --dangerously-skip-permissions, so the one-time accept gate would just trap every fresh box.",
|
|
3
3
|
"skipDangerousModePermissionPrompt": true,
|
|
4
4
|
"hooks": {
|
|
5
5
|
"UserPromptSubmit": [
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"Stop": [
|
|
46
46
|
{
|
|
47
47
|
"hooks": [
|
|
48
|
-
{ "type": "command", "command": "agentbox-ctl claude-state idle >/dev/null 2>&1
|
|
48
|
+
{ "type": "command", "command": "agentbox-ctl claude-state idle --capture-session >/dev/null 2>&1", "timeout": 3 }
|
|
49
49
|
]
|
|
50
50
|
}
|
|
51
51
|
],
|
|
@@ -101,14 +101,14 @@
|
|
|
101
101
|
"SessionStart": [
|
|
102
102
|
{
|
|
103
103
|
"hooks": [
|
|
104
|
-
{ "type": "command", "command": "agentbox-ctl claude-state idle >/dev/null 2>&1
|
|
104
|
+
{ "type": "command", "command": "agentbox-ctl claude-state idle --capture-session >/dev/null 2>&1", "timeout": 3 }
|
|
105
105
|
]
|
|
106
106
|
}
|
|
107
107
|
],
|
|
108
108
|
"SessionEnd": [
|
|
109
109
|
{
|
|
110
110
|
"hooks": [
|
|
111
|
-
{ "type": "command", "command": "agentbox-ctl claude-state idle >/dev/null 2>&1 &", "timeout": 3 }
|
|
111
|
+
{ "type": "command", "command": "agentbox-ctl claude-state idle --clear-session >/dev/null 2>&1 &", "timeout": 3 }
|
|
112
112
|
]
|
|
113
113
|
}
|
|
114
114
|
]
|