#!/usr/bin/env node /** * PUBLIC DOMAIN - NO LICENSE, NO WARRANTY * * unsandbox.com JavaScript SDK (Synchronous/Async) * Isomorphic: Works in Node.js (CLI + SDK) and Browser environments * * Library Usage (ES Modules): * import { * // Code execution * executeCode, executeAsync, getJob, waitForJob, cancelJob, listJobs, * getLanguages, detectLanguage, * // Session management * listSessions, getSession, createSession, deleteSession, * freezeSession, unfreezeSession, boostSession, unboostSession, shellSession, * // Service management * listServices, createService, getService, updateService, deleteService, * freezeService, unfreezeService, lockService, unlockService, setUnfreezeOnDemand, setShowFreezePage, * getServiceLogs, getServiceEnv, setServiceEnv, deleteServiceEnv, * exportServiceEnv, redeployService, executeInService, * // Snapshot management * sessionSnapshot, serviceSnapshot, listSnapshots, restoreSnapshot, * deleteSnapshot, lockSnapshot, unlockSnapshot, cloneSnapshot, * // Images API (LXD container images) * imagePublish, listImages, getImage, deleteImage, * lockImage, unlockImage, setImageVisibility, * grantImageAccess, revokeImageAccess, listImageTrusted, * transferImage, spawnFromImage, cloneImage, * // Key validation * validateKeys, * } from './un.js'; * * // Execute code asynchronously (returns Promise) * const result = await executeCode('python', 'print("hello")', publicKey, secretKey); * const jobId = await executeAsync('javascript', 'console.log("hello")', publicKey, secretKey); * const result = await waitForJob(jobId, publicKey, secretKey); * * Authentication Priority (5-tier): * 1. Function arguments (publicKey, secretKey) * 2. Environment variables (UNSANDBOX_PUBLIC_KEY, UNSANDBOX_SECRET_KEY) [Node.js] * 3. Encrypted vault or localStorage [Browser] (vault preferred if CryptoJS available) * 4. ~/.unsandbox/accounts.csv [Node.js] * 5. ./accounts.csv [Node.js] * * Request Authentication (HMAC-SHA256): * Authorization: Bearer * X-Timestamp: * X-Signature: HMAC-SHA256(secretKey, "timestamp:METHOD:path:body") * * Languages Cache: * - Cached in ~/.unsandbox/languages.json (Node.js only) * - TTL: 1 hour * - Updated on successful API calls * * Browser Usage: * - Import as ES module: