UNPKG

@luxorai/sandbox

Version:

TypeScript SDK for Luxor Sandbox: cloud sandboxes (microVMs) for AI agents on Luxor Agent Cloud

45 lines • 1.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isDiskExhausted = isDiskExhausted; exports.diskUsedBytes = diskUsedBytes; exports.diskUsedPercent = diskUsedPercent; /** * Free-space floor under which a run is treated as having exhausted the disk. * Not zero: allocators fail short of the last byte, and ext4 keeps a root * reserve the workload cannot touch, so a workload-visible "full" disk still * reports a small non-zero available figure. */ const DISK_EXHAUSTION_AVAILABLE_BYTES = 16 * 1024 * 1024; /** * Whether the sandbox filesystem ran out of usable space at any point during * the command. Deliberately independent of exit status: npm hits ENOSPC while * unpacking, prints it as a warning and still exits 0, leaving a broken install * behind, so a caller that only checks this on failure misses the case that is * hardest to diagnose. */ function isDiskExhausted(disk) { if (!disk || disk.totalBytes <= 0) return false; return disk.minAvailableBytes < DISK_EXHAUSTION_AVAILABLE_BYTES; } /** * Space consumed, counted as df does: total minus free, so the reserve is * neither used nor available. A guest too old to report `freeBytes` falls back * to treating the reserve as used, which overstates usage rather than inventing * headroom. */ function diskUsedBytes(disk) { if (!disk || disk.totalBytes <= 0) return 0; const free = disk.freeBytes > 0 ? disk.freeBytes : disk.availableBytes; return disk.totalBytes - free; } /** Usage as df reports it, against usable capacity rather than raw total. */ function diskUsedPercent(disk) { const used = diskUsedBytes(disk); const usable = used + (disk?.availableBytes ?? 0); if (usable <= 0) return 0; return (used / usable) * 100; } //# sourceMappingURL=disk.js.map