@computesdk/just-bash
Advanced tools
+0
-18
| import * as _computesdk_provider from '@computesdk/provider'; | ||
| import { Bash, BashOptions } from 'just-bash'; | ||
| /** | ||
| * just-bash-specific configuration options | ||
| */ | ||
| interface JustBashConfig { | ||
| /** Enable Python support via pyodide (disabled by default) */ | ||
| python?: boolean; | ||
| /** Initial files to populate in the virtual filesystem */ | ||
| files?: BashOptions['files']; | ||
| /** Initial environment variables */ | ||
| env?: Record<string, string>; | ||
| /** Working directory (defaults to /home/user) */ | ||
| cwd?: string; | ||
| /** | ||
| * Custom filesystem implementation. | ||
| * Defaults to InMemoryFs. Use OverlayFs for copy-on-write over a real directory, | ||
| * ReadWriteFs for direct disk access, or MountableFs to combine multiple filesystems. | ||
| */ | ||
| fs?: BashOptions['fs']; | ||
| /** | ||
| * Custom commands to register alongside built-in commands. | ||
| * Created with `defineCommand()` from just-bash. | ||
| */ | ||
| customCommands?: BashOptions['customCommands']; | ||
| /** Network configuration for commands like curl */ | ||
| network?: BashOptions['network']; | ||
| } | ||
| /** Internal sandbox state */ | ||
| interface JustBashSandbox { | ||
@@ -32,0 +14,0 @@ bash: Bash; |
+0
-18
| import * as _computesdk_provider from '@computesdk/provider'; | ||
| import { Bash, BashOptions } from 'just-bash'; | ||
| /** | ||
| * just-bash-specific configuration options | ||
| */ | ||
| interface JustBashConfig { | ||
| /** Enable Python support via pyodide (disabled by default) */ | ||
| python?: boolean; | ||
| /** Initial files to populate in the virtual filesystem */ | ||
| files?: BashOptions['files']; | ||
| /** Initial environment variables */ | ||
| env?: Record<string, string>; | ||
| /** Working directory (defaults to /home/user) */ | ||
| cwd?: string; | ||
| /** | ||
| * Custom filesystem implementation. | ||
| * Defaults to InMemoryFs. Use OverlayFs for copy-on-write over a real directory, | ||
| * ReadWriteFs for direct disk access, or MountableFs to combine multiple filesystems. | ||
| */ | ||
| fs?: BashOptions['fs']; | ||
| /** | ||
| * Custom commands to register alongside built-in commands. | ||
| * Created with `defineCommand()` from just-bash. | ||
| */ | ||
| customCommands?: BashOptions['customCommands']; | ||
| /** Network configuration for commands like curl */ | ||
| network?: BashOptions['network']; | ||
| } | ||
| /** Internal sandbox state */ | ||
| interface JustBashSandbox { | ||
@@ -32,0 +14,0 @@ bash: Bash; |
+27
-117
@@ -34,15 +34,10 @@ "use strict"; | ||
| sandbox: { | ||
| /** | ||
| * Create a new just-bash sandbox | ||
| */ | ||
| create: async (config, options) => { | ||
| const sandboxId = `just-bash-${(0, import_nanoid.nanoid)(10)}`; | ||
| const usePython = config.python ?? options?.runtime === "python"; | ||
| const bash = new import_just_bash.Bash({ | ||
| files: config.files, | ||
| env: { | ||
| ...config.env, | ||
| ...options?.envs | ||
| }, | ||
| env: { ...config.env, ...options?.envs }, | ||
| cwd: config.cwd || "/home/user", | ||
| python: config.python ?? options?.runtime === "python", | ||
| python: usePython, | ||
| fs: config.fs, | ||
@@ -52,14 +47,6 @@ customCommands: config.customCommands, | ||
| }); | ||
| const sandbox = { | ||
| bash, | ||
| id: sandboxId, | ||
| createdAt: /* @__PURE__ */ new Date(), | ||
| config | ||
| }; | ||
| const sandbox = { bash, id: sandboxId, createdAt: /* @__PURE__ */ new Date(), config: { ...config, python: usePython } }; | ||
| activeSandboxes.set(sandboxId, sandbox); | ||
| return { sandbox, sandboxId }; | ||
| }, | ||
| /** | ||
| * Get an existing just-bash sandbox by ID | ||
| */ | ||
| getById: async (_config, sandboxId) => { | ||
@@ -70,26 +57,6 @@ const sandbox = activeSandboxes.get(sandboxId); | ||
| }, | ||
| /** | ||
| * List all active just-bash sandboxes | ||
| */ | ||
| list: async (_config) => { | ||
| return Array.from(activeSandboxes.entries()).map(([sandboxId, sandbox]) => ({ | ||
| sandbox, | ||
| sandboxId | ||
| })); | ||
| }, | ||
| /** | ||
| * Destroy a just-bash sandbox | ||
| */ | ||
| list: async (_config) => Array.from(activeSandboxes.entries()).map(([sandboxId, sandbox]) => ({ sandbox, sandboxId })), | ||
| destroy: async (_config, sandboxId) => { | ||
| activeSandboxes.delete(sandboxId); | ||
| }, | ||
| /** | ||
| * Execute code in the sandbox | ||
| * | ||
| * For Python: executes via the built-in python3 command (pyodide) | ||
| * For Node/JS: wraps code in a bash script that evaluates it | ||
| */ | ||
| /** | ||
| * Execute a shell command in the sandbox | ||
| */ | ||
| runCommand: async (sandbox, command, options) => { | ||
@@ -99,65 +66,26 @@ const startTime = Date.now(); | ||
| const execOptions = {}; | ||
| if (options?.env && Object.keys(options.env).length > 0) { | ||
| execOptions.env = options.env; | ||
| } | ||
| if (options?.cwd) { | ||
| execOptions.cwd = options.cwd; | ||
| } | ||
| const result = await sandbox.bash.exec( | ||
| command, | ||
| Object.keys(execOptions).length > 0 ? execOptions : void 0 | ||
| ); | ||
| return { | ||
| stdout: result.stdout || "", | ||
| stderr: result.stderr || "", | ||
| exitCode: result.exitCode, | ||
| durationMs: Date.now() - startTime | ||
| }; | ||
| if (options?.env && Object.keys(options.env).length > 0) execOptions.env = options.env; | ||
| if (options?.cwd) execOptions.cwd = options.cwd; | ||
| const result = await sandbox.bash.exec(command, Object.keys(execOptions).length > 0 ? execOptions : void 0); | ||
| return { stdout: result.stdout || "", stderr: result.stderr || "", exitCode: result.exitCode, durationMs: Date.now() - startTime }; | ||
| } catch (error) { | ||
| return { | ||
| stdout: "", | ||
| stderr: error instanceof Error ? error.message : String(error), | ||
| exitCode: 127, | ||
| durationMs: Date.now() - startTime | ||
| }; | ||
| return { stdout: "", stderr: error instanceof Error ? error.message : String(error), exitCode: 127, durationMs: Date.now() - startTime }; | ||
| } | ||
| }, | ||
| /** | ||
| * Get sandbox information | ||
| */ | ||
| getInfo: async (sandbox) => { | ||
| return { | ||
| id: sandbox.id, | ||
| provider: "just-bash", | ||
| runtime: sandbox.config.python ? "python" : "node", | ||
| status: "running", | ||
| createdAt: sandbox.createdAt, | ||
| timeout: 0, | ||
| // No timeout - local execution | ||
| metadata: { | ||
| type: "local", | ||
| cwd: sandbox.bash.getCwd() | ||
| } | ||
| }; | ||
| }, | ||
| /** | ||
| * Get URL for a port - not supported for local execution | ||
| */ | ||
| getInfo: async (sandbox) => ({ | ||
| id: sandbox.id, | ||
| provider: "just-bash", | ||
| status: "running", | ||
| createdAt: sandbox.createdAt, | ||
| timeout: 0, | ||
| metadata: { type: "local", cwd: sandbox.bash.getCwd(), python: sandbox.config.python } | ||
| }), | ||
| getUrl: async (_sandbox, options) => { | ||
| throw new Error( | ||
| `just-bash is a local sandbox without network capabilities. Cannot expose port ${options.port}.` | ||
| ); | ||
| throw new Error(`just-bash is a local sandbox without network capabilities. Cannot expose port ${options.port}.`); | ||
| }, | ||
| /** | ||
| * Filesystem operations using the just-bash virtual filesystem | ||
| */ | ||
| filesystem: { | ||
| readFile: async (sandbox, path, _runCommand) => { | ||
| return sandbox.bash.readFile(path); | ||
| }, | ||
| readFile: async (sandbox, path, _runCommand) => sandbox.bash.readFile(path), | ||
| writeFile: async (sandbox, path, content, _runCommand) => { | ||
| const parentDir = path.substring(0, path.lastIndexOf("/")) || "/"; | ||
| if (parentDir !== "/") { | ||
| await sandbox.bash.exec(`mkdir -p ${parentDir}`); | ||
| } | ||
| if (parentDir !== "/") await sandbox.bash.exec(`mkdir -p ${parentDir}`); | ||
| await sandbox.bash.writeFile(path, content); | ||
@@ -167,26 +95,15 @@ }, | ||
| const result = await sandbox.bash.exec(`mkdir -p ${path}`); | ||
| if (result.exitCode !== 0) { | ||
| throw new Error(`Failed to create directory ${path}: ${result.stderr}`); | ||
| } | ||
| if (result.exitCode !== 0) throw new Error(`Failed to create directory ${path}: ${result.stderr}`); | ||
| }, | ||
| readdir: async (sandbox, path, _runCommand) => { | ||
| const result = await sandbox.bash.exec(`ls -la ${path}`); | ||
| if (result.exitCode !== 0) { | ||
| throw new Error(`Failed to list directory ${path}: ${result.stderr}`); | ||
| } | ||
| if (result.exitCode !== 0) throw new Error(`Failed to list directory ${path}: ${result.stderr}`); | ||
| const entries = []; | ||
| const lines = result.stdout.trim().split("\n"); | ||
| for (const line of lines) { | ||
| for (const line of result.stdout.trim().split("\n")) { | ||
| if (!line || line.startsWith("total")) continue; | ||
| const parts = line.split(/\s+/); | ||
| if (parts.length < 9) continue; | ||
| const permissions = parts[0]; | ||
| const name = parts.slice(8).join(" "); | ||
| if (name === "." || name === "..") continue; | ||
| entries.push({ | ||
| name, | ||
| type: permissions.startsWith("d") ? "directory" : "file", | ||
| size: parseInt(parts[4], 10) || 0, | ||
| modified: /* @__PURE__ */ new Date() | ||
| }); | ||
| entries.push({ name, type: parts[0].startsWith("d") ? "directory" : "file", size: parseInt(parts[4], 10) || 0, modified: /* @__PURE__ */ new Date() }); | ||
| } | ||
@@ -201,13 +118,6 @@ return entries; | ||
| const result = await sandbox.bash.exec(`rm -rf ${path}`); | ||
| if (result.exitCode !== 0) { | ||
| throw new Error(`Failed to remove ${path}: ${result.stderr}`); | ||
| } | ||
| if (result.exitCode !== 0) throw new Error(`Failed to remove ${path}: ${result.stderr}`); | ||
| } | ||
| }, | ||
| /** | ||
| * Get the native JustBashSandbox instance for advanced usage | ||
| */ | ||
| getInstance: (sandbox) => { | ||
| return sandbox; | ||
| } | ||
| getInstance: (sandbox) => sandbox | ||
| } | ||
@@ -214,0 +124,0 @@ } |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * just-bash Provider - Factory-based Implementation\n *\n * Local sandboxed bash execution using the just-bash package.\n * Provides a virtual filesystem and bash shell environment\n * without requiring any external services or containers.\n *\n * Features:\n * - Pure TypeScript bash interpreter (no real processes)\n * - In-memory virtual filesystem\n * - Python support via pyodide (optional)\n * - Shell command execution with 60+ built-in commands\n * - No authentication required - runs entirely locally\n */\n\nimport { Bash } from 'just-bash';\nimport type { BashExecResult, BashOptions } from 'just-bash';\nimport { nanoid } from 'nanoid';\nimport { defineProvider } from '@computesdk/provider';\nimport type {\n CodeResult,\n CommandResult,\n SandboxInfo,\n Runtime,\n CreateSandboxOptions,\n FileEntry,\n RunCommandOptions,\n} from 'computesdk';\n\n/**\n * just-bash-specific configuration options\n */\nexport interface JustBashConfig {\n /** Enable Python support via pyodide (disabled by default) */\n python?: boolean;\n /** Initial files to populate in the virtual filesystem */\n files?: BashOptions['files'];\n /** Initial environment variables */\n env?: Record<string, string>;\n /** Working directory (defaults to /home/user) */\n cwd?: string;\n /**\n * Custom filesystem implementation.\n * Defaults to InMemoryFs. Use OverlayFs for copy-on-write over a real directory,\n * ReadWriteFs for direct disk access, or MountableFs to combine multiple filesystems.\n */\n fs?: BashOptions['fs'];\n /**\n * Custom commands to register alongside built-in commands.\n * Created with `defineCommand()` from just-bash.\n */\n customCommands?: BashOptions['customCommands'];\n /** Network configuration for commands like curl */\n network?: BashOptions['network'];\n}\n\n/** Internal sandbox state */\ninterface JustBashSandbox {\n bash: Bash;\n id: string;\n createdAt: Date;\n config: JustBashConfig;\n}\n\n/** Active sandboxes registry */\nconst activeSandboxes = new Map<string, JustBashSandbox>();\n\n/**\n * Create a just-bash provider instance using the factory pattern\n *\n * just-bash provides local sandboxed bash execution with:\n * - Virtual filesystem (in-memory)\n * - 60+ built-in commands (cat, grep, sed, awk, jq, etc.)\n * - Python support via pyodide\n * - No external dependencies or authentication required\n */\nconst _provider = defineProvider<JustBashSandbox, JustBashConfig>({\n name: 'just-bash',\n methods: {\n sandbox: {\n /**\n * Create a new just-bash sandbox\n */\n create: async (config: JustBashConfig, options?: CreateSandboxOptions) => {\n const sandboxId = `just-bash-${nanoid(10)}`;\n\n const bash = new Bash({\n files: config.files,\n env: {\n ...config.env,\n ...options?.envs,\n },\n cwd: config.cwd || '/home/user',\n python: config.python ?? (options?.runtime === 'python'),\n fs: config.fs,\n customCommands: config.customCommands,\n network: config.network,\n });\n\n const sandbox: JustBashSandbox = {\n bash,\n id: sandboxId,\n createdAt: new Date(),\n config,\n };\n\n activeSandboxes.set(sandboxId, sandbox);\n return { sandbox, sandboxId };\n },\n\n /**\n * Get an existing just-bash sandbox by ID\n */\n getById: async (_config: JustBashConfig, sandboxId: string) => {\n const sandbox = activeSandboxes.get(sandboxId);\n if (!sandbox) return null;\n return { sandbox, sandboxId };\n },\n\n /**\n * List all active just-bash sandboxes\n */\n list: async (_config: JustBashConfig) => {\n return Array.from(activeSandboxes.entries()).map(([sandboxId, sandbox]) => ({\n sandbox,\n sandboxId,\n }));\n },\n\n /**\n * Destroy a just-bash sandbox\n */\n destroy: async (_config: JustBashConfig, sandboxId: string) => {\n activeSandboxes.delete(sandboxId);\n },\n\n /**\n * Execute code in the sandbox\n *\n * For Python: executes via the built-in python3 command (pyodide)\n * For Node/JS: wraps code in a bash script that evaluates it\n */\n\n /**\n * Execute a shell command in the sandbox\n */\n runCommand: async (sandbox: JustBashSandbox, command: string, options?: RunCommandOptions): Promise<CommandResult> => {\n const startTime = Date.now();\n try {\n const execOptions: { env?: Record<string, string>; cwd?: string } = {};\n\n if (options?.env && Object.keys(options.env).length > 0) {\n execOptions.env = options.env;\n }\n\n if (options?.cwd) {\n execOptions.cwd = options.cwd;\n }\n\n const result = await sandbox.bash.exec(\n command,\n Object.keys(execOptions).length > 0 ? execOptions : undefined\n );\n\n return {\n stdout: result.stdout || '',\n stderr: result.stderr || '',\n exitCode: result.exitCode,\n durationMs: Date.now() - startTime,\n };\n } catch (error) {\n return {\n stdout: '',\n stderr: error instanceof Error ? error.message : String(error),\n exitCode: 127,\n durationMs: Date.now() - startTime,\n };\n }\n },\n\n /**\n * Get sandbox information\n */\n getInfo: async (sandbox: JustBashSandbox): Promise<SandboxInfo> => {\n return {\n id: sandbox.id,\n provider: 'just-bash',\n runtime: sandbox.config.python ? 'python' : 'node',\n status: 'running',\n createdAt: sandbox.createdAt,\n timeout: 0, // No timeout - local execution\n metadata: {\n type: 'local',\n cwd: sandbox.bash.getCwd(),\n },\n };\n },\n\n /**\n * Get URL for a port - not supported for local execution\n */\n getUrl: async (_sandbox: JustBashSandbox, options: { port: number; protocol?: string }): Promise<string> => {\n throw new Error(\n `just-bash is a local sandbox without network capabilities. Cannot expose port ${options.port}.`\n );\n },\n\n /**\n * Filesystem operations using the just-bash virtual filesystem\n */\n filesystem: {\n readFile: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<string> => {\n return sandbox.bash.readFile(path);\n },\n\n writeFile: async (sandbox: JustBashSandbox, path: string, content: string, _runCommand): Promise<void> => {\n // Ensure parent directory exists\n const parentDir = path.substring(0, path.lastIndexOf('/')) || '/';\n if (parentDir !== '/') {\n await sandbox.bash.exec(`mkdir -p ${parentDir}`);\n }\n await sandbox.bash.writeFile(path, content);\n },\n\n mkdir: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<void> => {\n const result = await sandbox.bash.exec(`mkdir -p ${path}`);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to create directory ${path}: ${result.stderr}`);\n }\n },\n\n readdir: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<FileEntry[]> => {\n const result = await sandbox.bash.exec(`ls -la ${path}`);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to list directory ${path}: ${result.stderr}`);\n }\n\n const entries: FileEntry[] = [];\n const lines = result.stdout.trim().split('\\n');\n\n for (const line of lines) {\n // Skip total line and empty lines\n if (!line || line.startsWith('total')) continue;\n\n const parts = line.split(/\\s+/);\n if (parts.length < 9) continue;\n\n const permissions = parts[0];\n const name = parts.slice(8).join(' ');\n\n // Skip . and ..\n if (name === '.' || name === '..') continue;\n\n entries.push({\n name,\n type: permissions.startsWith('d') ? 'directory' as const : 'file' as const,\n size: parseInt(parts[4], 10) || 0,\n modified: new Date(),\n });\n }\n\n return entries;\n },\n\n exists: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<boolean> => {\n const result = await sandbox.bash.exec(`test -f ${path} || test -d ${path}`);\n return result.exitCode === 0;\n },\n\n remove: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<void> => {\n const result = await sandbox.bash.exec(`rm -rf ${path}`);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to remove ${path}: ${result.stderr}`);\n }\n },\n },\n\n /**\n * Get the native JustBashSandbox instance for advanced usage\n */\n getInstance: (sandbox: JustBashSandbox): JustBashSandbox => {\n return sandbox;\n },\n },\n },\n});\n\nexport const justBash = (config: JustBashConfig = {}) => _provider(config);\n\n// Export types\nexport type { JustBashSandbox };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,uBAAqB;AAErB,oBAAuB;AACvB,sBAA+B;AA+C/B,IAAM,kBAAkB,oBAAI,IAA6B;AAWzD,IAAM,gBAAY,gCAAgD;AAAA,EAChE,MAAM;AAAA,EACN,SAAS;AAAA,IACP,SAAS;AAAA;AAAA;AAAA;AAAA,MAIP,QAAQ,OAAO,QAAwB,YAAmC;AACxE,cAAM,YAAY,iBAAa,sBAAO,EAAE,CAAC;AAEzC,cAAM,OAAO,IAAI,sBAAK;AAAA,UACpB,OAAO,OAAO;AAAA,UACd,KAAK;AAAA,YACH,GAAG,OAAO;AAAA,YACV,GAAG,SAAS;AAAA,UACd;AAAA,UACA,KAAK,OAAO,OAAO;AAAA,UACnB,QAAQ,OAAO,UAAW,SAAS,YAAY;AAAA,UAC/C,IAAI,OAAO;AAAA,UACX,gBAAgB,OAAO;AAAA,UACvB,SAAS,OAAO;AAAA,QAClB,CAAC;AAED,cAAM,UAA2B;AAAA,UAC/B;AAAA,UACA,IAAI;AAAA,UACJ,WAAW,oBAAI,KAAK;AAAA,UACpB;AAAA,QACF;AAEA,wBAAgB,IAAI,WAAW,OAAO;AACtC,eAAO,EAAE,SAAS,UAAU;AAAA,MAC9B;AAAA;AAAA;AAAA;AAAA,MAKA,SAAS,OAAO,SAAyB,cAAsB;AAC7D,cAAM,UAAU,gBAAgB,IAAI,SAAS;AAC7C,YAAI,CAAC,QAAS,QAAO;AACrB,eAAO,EAAE,SAAS,UAAU;AAAA,MAC9B;AAAA;AAAA;AAAA;AAAA,MAKA,MAAM,OAAO,YAA4B;AACvC,eAAO,MAAM,KAAK,gBAAgB,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAC,WAAW,OAA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,MAAM,SAAS,EAAG;AAEtB,kBAAM,cAAc,MAAM,CAAC;AAC3B,kBAAM,OAAO,MAAM,MAAM,CAAC,EAAE,KAAK,GAAG;AAGpC,gBAAI,SAAS,OAAO,SAAS,KAAM;AAEnC,oBAAQ,KAAK;AAAA,cACX;AAAA,cACA,MAAM,YAAY,WAAW,GAAG,IAAI,cAAuB;AAAA,cAC3D,MAAM,SAAS,MAAM,CAAC,GAAG,EAAE,KAAK;AAAA,cAChC,UAAU,oBAAI,KAAK;AAAA,YACrB,CAAC;AAAA,UACH;AAEA,iBAAO;AAAA,QACT;AAAA,QAEA,QAAQ,OAAO,SAA0B,MAAc,gBAAkC;AACvF,gBAAM,SAAS,MAAM,QAAQ,KAAK,KAAK,WAAW,IAAI,eAAe,IAAI,EAAE;AAC3E,iBAAO,OAAO,aAAa;AAAA,QAC7B;AAAA,QAEA,QAAQ,OAAO,SAA0B,MAAc,gBAA+B;AACpF,gBAAM,SAAS,MAAM,QAAQ,KAAK,KAAK,UAAU,IAAI,EAAE;AACvD,cAAI,OAAO,aAAa,GAAG;AACzB,kBAAM,IAAI,MAAM,oBAAoB,IAAI,KAAK,OAAO,MAAM,EAAE;AAAA,UAC9D;AAAA,QACF;AAAA,MACF;AAAA;AAAA;AAAA;AAAA,MAKA,aAAa,CAAC,YAA8C;AAC1D,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAEM,IAAM,WAAW,CAAC,SAAyB,CAAC,MAAM,UAAU,MAAM;","names":[]} | ||
| {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * just-bash Provider - Factory-based Implementation\n *\n * Local sandboxed bash execution using the just-bash package.\n */\n\nimport { Bash } from 'just-bash';\nimport type { BashOptions } from 'just-bash';\nimport { nanoid } from 'nanoid';\nimport { defineProvider } from '@computesdk/provider';\nimport type {\n CommandResult,\n SandboxInfo,\n CreateSandboxOptions,\n FileEntry,\n RunCommandOptions,\n} from 'computesdk';\n\nexport interface JustBashConfig {\n python?: boolean;\n files?: BashOptions['files'];\n env?: Record<string, string>;\n cwd?: string;\n fs?: BashOptions['fs'];\n customCommands?: BashOptions['customCommands'];\n network?: BashOptions['network'];\n}\n\ninterface JustBashSandbox {\n bash: Bash;\n id: string;\n createdAt: Date;\n config: JustBashConfig;\n}\n\nconst activeSandboxes = new Map<string, JustBashSandbox>();\n\nconst _provider = defineProvider<JustBashSandbox, JustBashConfig>({\n name: 'just-bash',\n methods: {\n sandbox: {\n create: async (config: JustBashConfig, options?: CreateSandboxOptions) => {\n const sandboxId = `just-bash-${nanoid(10)}`;\n const usePython = config.python ?? ((options as any)?.runtime === 'python');\n const bash = new Bash({\n files: config.files,\n env: { ...config.env, ...options?.envs },\n cwd: config.cwd || '/home/user',\n python: usePython,\n fs: config.fs,\n customCommands: config.customCommands,\n network: config.network,\n });\n const sandbox: JustBashSandbox = { bash, id: sandboxId, createdAt: new Date(), config: { ...config, python: usePython } };\n activeSandboxes.set(sandboxId, sandbox);\n return { sandbox, sandboxId };\n },\n\n getById: async (_config: JustBashConfig, sandboxId: string) => {\n const sandbox = activeSandboxes.get(sandboxId);\n if (!sandbox) return null;\n return { sandbox, sandboxId };\n },\n\n list: async (_config: JustBashConfig) =>\n Array.from(activeSandboxes.entries()).map(([sandboxId, sandbox]) => ({ sandbox, sandboxId })),\n\n destroy: async (_config: JustBashConfig, sandboxId: string) => {\n activeSandboxes.delete(sandboxId);\n },\n\n runCommand: async (sandbox: JustBashSandbox, command: string, options?: RunCommandOptions): Promise<CommandResult> => {\n const startTime = Date.now();\n try {\n const execOptions: { env?: Record<string, string>; cwd?: string } = {};\n if (options?.env && Object.keys(options.env).length > 0) execOptions.env = options.env;\n if (options?.cwd) execOptions.cwd = options.cwd;\n const result = await sandbox.bash.exec(command, Object.keys(execOptions).length > 0 ? execOptions : undefined);\n return { stdout: result.stdout || '', stderr: result.stderr || '', exitCode: result.exitCode, durationMs: Date.now() - startTime };\n } catch (error) {\n return { stdout: '', stderr: error instanceof Error ? error.message : String(error), exitCode: 127, durationMs: Date.now() - startTime };\n }\n },\n\n getInfo: async (sandbox: JustBashSandbox): Promise<SandboxInfo> => ({\n id: sandbox.id,\n provider: 'just-bash',\n status: 'running',\n createdAt: sandbox.createdAt,\n timeout: 0,\n metadata: { type: 'local', cwd: sandbox.bash.getCwd(), python: sandbox.config.python },\n }),\n\n getUrl: async (_sandbox: JustBashSandbox, options: { port: number; protocol?: string }): Promise<string> => {\n throw new Error(`just-bash is a local sandbox without network capabilities. Cannot expose port ${options.port}.`);\n },\n\n filesystem: {\n readFile: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<string> =>\n sandbox.bash.readFile(path),\n writeFile: async (sandbox: JustBashSandbox, path: string, content: string, _runCommand): Promise<void> => {\n const parentDir = path.substring(0, path.lastIndexOf('/')) || '/';\n if (parentDir !== '/') await sandbox.bash.exec(`mkdir -p ${parentDir}`);\n await sandbox.bash.writeFile(path, content);\n },\n mkdir: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<void> => {\n const result = await sandbox.bash.exec(`mkdir -p ${path}`);\n if (result.exitCode !== 0) throw new Error(`Failed to create directory ${path}: ${result.stderr}`);\n },\n readdir: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<FileEntry[]> => {\n const result = await sandbox.bash.exec(`ls -la ${path}`);\n if (result.exitCode !== 0) throw new Error(`Failed to list directory ${path}: ${result.stderr}`);\n const entries: FileEntry[] = [];\n for (const line of result.stdout.trim().split('\\n')) {\n if (!line || line.startsWith('total')) continue;\n const parts = line.split(/\\s+/);\n if (parts.length < 9) continue;\n const name = parts.slice(8).join(' ');\n if (name === '.' || name === '..') continue;\n entries.push({ name, type: parts[0].startsWith('d') ? 'directory' as const : 'file' as const, size: parseInt(parts[4], 10) || 0, modified: new Date() });\n }\n return entries;\n },\n exists: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<boolean> => {\n const result = await sandbox.bash.exec(`test -f ${path} || test -d ${path}`);\n return result.exitCode === 0;\n },\n remove: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<void> => {\n const result = await sandbox.bash.exec(`rm -rf ${path}`);\n if (result.exitCode !== 0) throw new Error(`Failed to remove ${path}: ${result.stderr}`);\n },\n },\n\n getInstance: (sandbox: JustBashSandbox): JustBashSandbox => sandbox,\n },\n },\n});\n\nexport const justBash = (config: JustBashConfig = {}) => _provider(config);\nexport type { JustBashSandbox };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,uBAAqB;AAErB,oBAAuB;AACvB,sBAA+B;AA0B/B,IAAM,kBAAkB,oBAAI,IAA6B;AAEzD,IAAM,gBAAY,gCAAgD;AAAA,EAChE,MAAM;AAAA,EACN,SAAS;AAAA,IACP,SAAS;AAAA,MACP,QAAQ,OAAO,QAAwB,YAAmC;AACxE,cAAM,YAAY,iBAAa,sBAAO,EAAE,CAAC;AACzC,cAAM,YAAY,OAAO,UAAY,SAAiB,YAAY;AAClE,cAAM,OAAO,IAAI,sBAAK;AAAA,UACpB,OAAO,OAAO;AAAA,UACd,KAAK,EAAE,GAAG,OAAO,KAAK,GAAG,SAAS,KAAK;AAAA,UACvC,KAAK,OAAO,OAAO;AAAA,UACnB,QAAQ;AAAA,UACR,IAAI,OAAO;AAAA,UACX,gBAAgB,OAAO;AAAA,UACvB,SAAS,OAAO;AAAA,QAClB,CAAC;AACD,cAAM,UAA2B,EAAE,MAAM,IAAI,WAAW,WAAW,oBAAI,KAAK,GAAG,QAAQ,EAAE,GAAG,QAAQ,QAAQ,UAAU,EAAE;AACxH,wBAAgB,IAAI,WAAW,OAAO;AACtC,eAAO,EAAE,SAAS,UAAU;AAAA,MAC9B;AAAA,MAEA,SAAS,OAAO,SAAyB,cAAsB;AAC7D,cAAM,UAAU,gBAAgB,IAAI,SAAS;AAC7C,YAAI,CAAC,QAAS,QAAO;AACrB,eAAO,EAAE,SAAS,UAAU;AAAA,MAC9B;AAAA,MAEA,MAAM,OAAO,YACX,MAAM,KA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AM,QAAQ,KAAK,KAAK,WAAW,IAAI,eAAe,IAAI,EAAE;AAC3E,iBAAO,OAAO,aAAa;AAAA,QAC7B;AAAA,QACA,QAAQ,OAAO,SAA0B,MAAc,gBAA+B;AACpF,gBAAM,SAAS,MAAM,QAAQ,KAAK,KAAK,UAAU,IAAI,EAAE;AACvD,cAAI,OAAO,aAAa,EAAG,OAAM,IAAI,MAAM,oBAAoB,IAAI,KAAK,OAAO,MAAM,EAAE;AAAA,QACzF;AAAA,MACF;AAAA,MAEA,aAAa,CAAC,YAA8C;AAAA,IAC9D;AAAA,EACF;AACF,CAAC;AAEM,IAAM,WAAW,CAAC,SAAyB,CAAC,MAAM,UAAU,MAAM;","names":[]} |
+27
-117
@@ -10,15 +10,10 @@ // src/index.ts | ||
| sandbox: { | ||
| /** | ||
| * Create a new just-bash sandbox | ||
| */ | ||
| create: async (config, options) => { | ||
| const sandboxId = `just-bash-${nanoid(10)}`; | ||
| const usePython = config.python ?? options?.runtime === "python"; | ||
| const bash = new Bash({ | ||
| files: config.files, | ||
| env: { | ||
| ...config.env, | ||
| ...options?.envs | ||
| }, | ||
| env: { ...config.env, ...options?.envs }, | ||
| cwd: config.cwd || "/home/user", | ||
| python: config.python ?? options?.runtime === "python", | ||
| python: usePython, | ||
| fs: config.fs, | ||
@@ -28,14 +23,6 @@ customCommands: config.customCommands, | ||
| }); | ||
| const sandbox = { | ||
| bash, | ||
| id: sandboxId, | ||
| createdAt: /* @__PURE__ */ new Date(), | ||
| config | ||
| }; | ||
| const sandbox = { bash, id: sandboxId, createdAt: /* @__PURE__ */ new Date(), config: { ...config, python: usePython } }; | ||
| activeSandboxes.set(sandboxId, sandbox); | ||
| return { sandbox, sandboxId }; | ||
| }, | ||
| /** | ||
| * Get an existing just-bash sandbox by ID | ||
| */ | ||
| getById: async (_config, sandboxId) => { | ||
@@ -46,26 +33,6 @@ const sandbox = activeSandboxes.get(sandboxId); | ||
| }, | ||
| /** | ||
| * List all active just-bash sandboxes | ||
| */ | ||
| list: async (_config) => { | ||
| return Array.from(activeSandboxes.entries()).map(([sandboxId, sandbox]) => ({ | ||
| sandbox, | ||
| sandboxId | ||
| })); | ||
| }, | ||
| /** | ||
| * Destroy a just-bash sandbox | ||
| */ | ||
| list: async (_config) => Array.from(activeSandboxes.entries()).map(([sandboxId, sandbox]) => ({ sandbox, sandboxId })), | ||
| destroy: async (_config, sandboxId) => { | ||
| activeSandboxes.delete(sandboxId); | ||
| }, | ||
| /** | ||
| * Execute code in the sandbox | ||
| * | ||
| * For Python: executes via the built-in python3 command (pyodide) | ||
| * For Node/JS: wraps code in a bash script that evaluates it | ||
| */ | ||
| /** | ||
| * Execute a shell command in the sandbox | ||
| */ | ||
| runCommand: async (sandbox, command, options) => { | ||
@@ -75,65 +42,26 @@ const startTime = Date.now(); | ||
| const execOptions = {}; | ||
| if (options?.env && Object.keys(options.env).length > 0) { | ||
| execOptions.env = options.env; | ||
| } | ||
| if (options?.cwd) { | ||
| execOptions.cwd = options.cwd; | ||
| } | ||
| const result = await sandbox.bash.exec( | ||
| command, | ||
| Object.keys(execOptions).length > 0 ? execOptions : void 0 | ||
| ); | ||
| return { | ||
| stdout: result.stdout || "", | ||
| stderr: result.stderr || "", | ||
| exitCode: result.exitCode, | ||
| durationMs: Date.now() - startTime | ||
| }; | ||
| if (options?.env && Object.keys(options.env).length > 0) execOptions.env = options.env; | ||
| if (options?.cwd) execOptions.cwd = options.cwd; | ||
| const result = await sandbox.bash.exec(command, Object.keys(execOptions).length > 0 ? execOptions : void 0); | ||
| return { stdout: result.stdout || "", stderr: result.stderr || "", exitCode: result.exitCode, durationMs: Date.now() - startTime }; | ||
| } catch (error) { | ||
| return { | ||
| stdout: "", | ||
| stderr: error instanceof Error ? error.message : String(error), | ||
| exitCode: 127, | ||
| durationMs: Date.now() - startTime | ||
| }; | ||
| return { stdout: "", stderr: error instanceof Error ? error.message : String(error), exitCode: 127, durationMs: Date.now() - startTime }; | ||
| } | ||
| }, | ||
| /** | ||
| * Get sandbox information | ||
| */ | ||
| getInfo: async (sandbox) => { | ||
| return { | ||
| id: sandbox.id, | ||
| provider: "just-bash", | ||
| runtime: sandbox.config.python ? "python" : "node", | ||
| status: "running", | ||
| createdAt: sandbox.createdAt, | ||
| timeout: 0, | ||
| // No timeout - local execution | ||
| metadata: { | ||
| type: "local", | ||
| cwd: sandbox.bash.getCwd() | ||
| } | ||
| }; | ||
| }, | ||
| /** | ||
| * Get URL for a port - not supported for local execution | ||
| */ | ||
| getInfo: async (sandbox) => ({ | ||
| id: sandbox.id, | ||
| provider: "just-bash", | ||
| status: "running", | ||
| createdAt: sandbox.createdAt, | ||
| timeout: 0, | ||
| metadata: { type: "local", cwd: sandbox.bash.getCwd(), python: sandbox.config.python } | ||
| }), | ||
| getUrl: async (_sandbox, options) => { | ||
| throw new Error( | ||
| `just-bash is a local sandbox without network capabilities. Cannot expose port ${options.port}.` | ||
| ); | ||
| throw new Error(`just-bash is a local sandbox without network capabilities. Cannot expose port ${options.port}.`); | ||
| }, | ||
| /** | ||
| * Filesystem operations using the just-bash virtual filesystem | ||
| */ | ||
| filesystem: { | ||
| readFile: async (sandbox, path, _runCommand) => { | ||
| return sandbox.bash.readFile(path); | ||
| }, | ||
| readFile: async (sandbox, path, _runCommand) => sandbox.bash.readFile(path), | ||
| writeFile: async (sandbox, path, content, _runCommand) => { | ||
| const parentDir = path.substring(0, path.lastIndexOf("/")) || "/"; | ||
| if (parentDir !== "/") { | ||
| await sandbox.bash.exec(`mkdir -p ${parentDir}`); | ||
| } | ||
| if (parentDir !== "/") await sandbox.bash.exec(`mkdir -p ${parentDir}`); | ||
| await sandbox.bash.writeFile(path, content); | ||
@@ -143,26 +71,15 @@ }, | ||
| const result = await sandbox.bash.exec(`mkdir -p ${path}`); | ||
| if (result.exitCode !== 0) { | ||
| throw new Error(`Failed to create directory ${path}: ${result.stderr}`); | ||
| } | ||
| if (result.exitCode !== 0) throw new Error(`Failed to create directory ${path}: ${result.stderr}`); | ||
| }, | ||
| readdir: async (sandbox, path, _runCommand) => { | ||
| const result = await sandbox.bash.exec(`ls -la ${path}`); | ||
| if (result.exitCode !== 0) { | ||
| throw new Error(`Failed to list directory ${path}: ${result.stderr}`); | ||
| } | ||
| if (result.exitCode !== 0) throw new Error(`Failed to list directory ${path}: ${result.stderr}`); | ||
| const entries = []; | ||
| const lines = result.stdout.trim().split("\n"); | ||
| for (const line of lines) { | ||
| for (const line of result.stdout.trim().split("\n")) { | ||
| if (!line || line.startsWith("total")) continue; | ||
| const parts = line.split(/\s+/); | ||
| if (parts.length < 9) continue; | ||
| const permissions = parts[0]; | ||
| const name = parts.slice(8).join(" "); | ||
| if (name === "." || name === "..") continue; | ||
| entries.push({ | ||
| name, | ||
| type: permissions.startsWith("d") ? "directory" : "file", | ||
| size: parseInt(parts[4], 10) || 0, | ||
| modified: /* @__PURE__ */ new Date() | ||
| }); | ||
| entries.push({ name, type: parts[0].startsWith("d") ? "directory" : "file", size: parseInt(parts[4], 10) || 0, modified: /* @__PURE__ */ new Date() }); | ||
| } | ||
@@ -177,13 +94,6 @@ return entries; | ||
| const result = await sandbox.bash.exec(`rm -rf ${path}`); | ||
| if (result.exitCode !== 0) { | ||
| throw new Error(`Failed to remove ${path}: ${result.stderr}`); | ||
| } | ||
| if (result.exitCode !== 0) throw new Error(`Failed to remove ${path}: ${result.stderr}`); | ||
| } | ||
| }, | ||
| /** | ||
| * Get the native JustBashSandbox instance for advanced usage | ||
| */ | ||
| getInstance: (sandbox) => { | ||
| return sandbox; | ||
| } | ||
| getInstance: (sandbox) => sandbox | ||
| } | ||
@@ -190,0 +100,0 @@ } |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * just-bash Provider - Factory-based Implementation\n *\n * Local sandboxed bash execution using the just-bash package.\n * Provides a virtual filesystem and bash shell environment\n * without requiring any external services or containers.\n *\n * Features:\n * - Pure TypeScript bash interpreter (no real processes)\n * - In-memory virtual filesystem\n * - Python support via pyodide (optional)\n * - Shell command execution with 60+ built-in commands\n * - No authentication required - runs entirely locally\n */\n\nimport { Bash } from 'just-bash';\nimport type { BashExecResult, BashOptions } from 'just-bash';\nimport { nanoid } from 'nanoid';\nimport { defineProvider } from '@computesdk/provider';\nimport type {\n CodeResult,\n CommandResult,\n SandboxInfo,\n Runtime,\n CreateSandboxOptions,\n FileEntry,\n RunCommandOptions,\n} from 'computesdk';\n\n/**\n * just-bash-specific configuration options\n */\nexport interface JustBashConfig {\n /** Enable Python support via pyodide (disabled by default) */\n python?: boolean;\n /** Initial files to populate in the virtual filesystem */\n files?: BashOptions['files'];\n /** Initial environment variables */\n env?: Record<string, string>;\n /** Working directory (defaults to /home/user) */\n cwd?: string;\n /**\n * Custom filesystem implementation.\n * Defaults to InMemoryFs. Use OverlayFs for copy-on-write over a real directory,\n * ReadWriteFs for direct disk access, or MountableFs to combine multiple filesystems.\n */\n fs?: BashOptions['fs'];\n /**\n * Custom commands to register alongside built-in commands.\n * Created with `defineCommand()` from just-bash.\n */\n customCommands?: BashOptions['customCommands'];\n /** Network configuration for commands like curl */\n network?: BashOptions['network'];\n}\n\n/** Internal sandbox state */\ninterface JustBashSandbox {\n bash: Bash;\n id: string;\n createdAt: Date;\n config: JustBashConfig;\n}\n\n/** Active sandboxes registry */\nconst activeSandboxes = new Map<string, JustBashSandbox>();\n\n/**\n * Create a just-bash provider instance using the factory pattern\n *\n * just-bash provides local sandboxed bash execution with:\n * - Virtual filesystem (in-memory)\n * - 60+ built-in commands (cat, grep, sed, awk, jq, etc.)\n * - Python support via pyodide\n * - No external dependencies or authentication required\n */\nconst _provider = defineProvider<JustBashSandbox, JustBashConfig>({\n name: 'just-bash',\n methods: {\n sandbox: {\n /**\n * Create a new just-bash sandbox\n */\n create: async (config: JustBashConfig, options?: CreateSandboxOptions) => {\n const sandboxId = `just-bash-${nanoid(10)}`;\n\n const bash = new Bash({\n files: config.files,\n env: {\n ...config.env,\n ...options?.envs,\n },\n cwd: config.cwd || '/home/user',\n python: config.python ?? (options?.runtime === 'python'),\n fs: config.fs,\n customCommands: config.customCommands,\n network: config.network,\n });\n\n const sandbox: JustBashSandbox = {\n bash,\n id: sandboxId,\n createdAt: new Date(),\n config,\n };\n\n activeSandboxes.set(sandboxId, sandbox);\n return { sandbox, sandboxId };\n },\n\n /**\n * Get an existing just-bash sandbox by ID\n */\n getById: async (_config: JustBashConfig, sandboxId: string) => {\n const sandbox = activeSandboxes.get(sandboxId);\n if (!sandbox) return null;\n return { sandbox, sandboxId };\n },\n\n /**\n * List all active just-bash sandboxes\n */\n list: async (_config: JustBashConfig) => {\n return Array.from(activeSandboxes.entries()).map(([sandboxId, sandbox]) => ({\n sandbox,\n sandboxId,\n }));\n },\n\n /**\n * Destroy a just-bash sandbox\n */\n destroy: async (_config: JustBashConfig, sandboxId: string) => {\n activeSandboxes.delete(sandboxId);\n },\n\n /**\n * Execute code in the sandbox\n *\n * For Python: executes via the built-in python3 command (pyodide)\n * For Node/JS: wraps code in a bash script that evaluates it\n */\n\n /**\n * Execute a shell command in the sandbox\n */\n runCommand: async (sandbox: JustBashSandbox, command: string, options?: RunCommandOptions): Promise<CommandResult> => {\n const startTime = Date.now();\n try {\n const execOptions: { env?: Record<string, string>; cwd?: string } = {};\n\n if (options?.env && Object.keys(options.env).length > 0) {\n execOptions.env = options.env;\n }\n\n if (options?.cwd) {\n execOptions.cwd = options.cwd;\n }\n\n const result = await sandbox.bash.exec(\n command,\n Object.keys(execOptions).length > 0 ? execOptions : undefined\n );\n\n return {\n stdout: result.stdout || '',\n stderr: result.stderr || '',\n exitCode: result.exitCode,\n durationMs: Date.now() - startTime,\n };\n } catch (error) {\n return {\n stdout: '',\n stderr: error instanceof Error ? error.message : String(error),\n exitCode: 127,\n durationMs: Date.now() - startTime,\n };\n }\n },\n\n /**\n * Get sandbox information\n */\n getInfo: async (sandbox: JustBashSandbox): Promise<SandboxInfo> => {\n return {\n id: sandbox.id,\n provider: 'just-bash',\n runtime: sandbox.config.python ? 'python' : 'node',\n status: 'running',\n createdAt: sandbox.createdAt,\n timeout: 0, // No timeout - local execution\n metadata: {\n type: 'local',\n cwd: sandbox.bash.getCwd(),\n },\n };\n },\n\n /**\n * Get URL for a port - not supported for local execution\n */\n getUrl: async (_sandbox: JustBashSandbox, options: { port: number; protocol?: string }): Promise<string> => {\n throw new Error(\n `just-bash is a local sandbox without network capabilities. Cannot expose port ${options.port}.`\n );\n },\n\n /**\n * Filesystem operations using the just-bash virtual filesystem\n */\n filesystem: {\n readFile: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<string> => {\n return sandbox.bash.readFile(path);\n },\n\n writeFile: async (sandbox: JustBashSandbox, path: string, content: string, _runCommand): Promise<void> => {\n // Ensure parent directory exists\n const parentDir = path.substring(0, path.lastIndexOf('/')) || '/';\n if (parentDir !== '/') {\n await sandbox.bash.exec(`mkdir -p ${parentDir}`);\n }\n await sandbox.bash.writeFile(path, content);\n },\n\n mkdir: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<void> => {\n const result = await sandbox.bash.exec(`mkdir -p ${path}`);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to create directory ${path}: ${result.stderr}`);\n }\n },\n\n readdir: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<FileEntry[]> => {\n const result = await sandbox.bash.exec(`ls -la ${path}`);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to list directory ${path}: ${result.stderr}`);\n }\n\n const entries: FileEntry[] = [];\n const lines = result.stdout.trim().split('\\n');\n\n for (const line of lines) {\n // Skip total line and empty lines\n if (!line || line.startsWith('total')) continue;\n\n const parts = line.split(/\\s+/);\n if (parts.length < 9) continue;\n\n const permissions = parts[0];\n const name = parts.slice(8).join(' ');\n\n // Skip . and ..\n if (name === '.' || name === '..') continue;\n\n entries.push({\n name,\n type: permissions.startsWith('d') ? 'directory' as const : 'file' as const,\n size: parseInt(parts[4], 10) || 0,\n modified: new Date(),\n });\n }\n\n return entries;\n },\n\n exists: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<boolean> => {\n const result = await sandbox.bash.exec(`test -f ${path} || test -d ${path}`);\n return result.exitCode === 0;\n },\n\n remove: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<void> => {\n const result = await sandbox.bash.exec(`rm -rf ${path}`);\n if (result.exitCode !== 0) {\n throw new Error(`Failed to remove ${path}: ${result.stderr}`);\n }\n },\n },\n\n /**\n * Get the native JustBashSandbox instance for advanced usage\n */\n getInstance: (sandbox: JustBashSandbox): JustBashSandbox => {\n return sandbox;\n },\n },\n },\n});\n\nexport const justBash = (config: JustBashConfig = {}) => _provider(config);\n\n// Export types\nexport type { JustBashSandbox };\n"],"mappings":";AAeA,SAAS,YAAY;AAErB,SAAS,cAAc;AACvB,SAAS,sBAAsB;AA+C/B,IAAM,kBAAkB,oBAAI,IAA6B;AAWzD,IAAM,YAAY,eAAgD;AAAA,EAChE,MAAM;AAAA,EACN,SAAS;AAAA,IACP,SAAS;AAAA;AAAA;AAAA;AAAA,MAIP,QAAQ,OAAO,QAAwB,YAAmC;AACxE,cAAM,YAAY,aAAa,OAAO,EAAE,CAAC;AAEzC,cAAM,OAAO,IAAI,KAAK;AAAA,UACpB,OAAO,OAAO;AAAA,UACd,KAAK;AAAA,YACH,GAAG,OAAO;AAAA,YACV,GAAG,SAAS;AAAA,UACd;AAAA,UACA,KAAK,OAAO,OAAO;AAAA,UACnB,QAAQ,OAAO,UAAW,SAAS,YAAY;AAAA,UAC/C,IAAI,OAAO;AAAA,UACX,gBAAgB,OAAO;AAAA,UACvB,SAAS,OAAO;AAAA,QAClB,CAAC;AAED,cAAM,UAA2B;AAAA,UAC/B;AAAA,UACA,IAAI;AAAA,UACJ,WAAW,oBAAI,KAAK;AAAA,UACpB;AAAA,QACF;AAEA,wBAAgB,IAAI,WAAW,OAAO;AACtC,eAAO,EAAE,SAAS,UAAU;AAAA,MAC9B;AAAA;AAAA;AAAA;AAAA,MAKA,SAAS,OAAO,SAAyB,cAAsB;AAC7D,cAAM,UAA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\n * Local sandboxed bash execution using the just-bash package.\n */\n\nimport { Bash } from 'just-bash';\nimport type { BashOptions } from 'just-bash';\nimport { nanoid } from 'nanoid';\nimport { defineProvider } from '@computesdk/provider';\nimport type {\n CommandResult,\n SandboxInfo,\n CreateSandboxOptions,\n FileEntry,\n RunCommandOptions,\n} from 'computesdk';\n\nexport interface JustBashConfig {\n python?: boolean;\n files?: BashOptions['files'];\n env?: Record<string, string>;\n cwd?: string;\n fs?: BashOptions['fs'];\n customCommands?: BashOptions['customCommands'];\n network?: BashOptions['network'];\n}\n\ninterface JustBashSandbox {\n bash: Bash;\n id: string;\n createdAt: Date;\n config: JustBashConfig;\n}\n\nconst activeSandboxes = new Map<string, JustBashSandbox>();\n\nconst _provider = defineProvider<JustBashSandbox, JustBashConfig>({\n name: 'just-bash',\n methods: {\n sandbox: {\n create: async (config: JustBashConfig, options?: CreateSandboxOptions) => {\n const sandboxId = `just-bash-${nanoid(10)}`;\n const usePython = config.python ?? ((options as any)?.runtime === 'python');\n const bash = new Bash({\n files: config.files,\n env: { ...config.env, ...options?.envs },\n cwd: config.cwd || '/home/user',\n python: usePython,\n fs: config.fs,\n customCommands: config.customCommands,\n network: config.network,\n });\n const sandbox: JustBashSandbox = { bash, id: sandboxId, createdAt: new Date(), config: { ...config, python: usePython } };\n activeSandboxes.set(sandboxId, sandbox);\n return { sandbox, sandboxId };\n },\n\n getById: async (_config: JustBashConfig, sandboxId: string) => {\n const sandbox = activeSandboxes.get(sandboxId);\n if (!sandbox) return null;\n return { sandbox, sandboxId };\n },\n\n list: async (_config: JustBashConfig) =>\n Array.from(activeSandboxes.entries()).map(([sandboxId, sandbox]) => ({ sandbox, sandboxId })),\n\n destroy: async (_config: JustBashConfig, sandboxId: string) => {\n activeSandboxes.delete(sandboxId);\n },\n\n runCommand: async (sandbox: JustBashSandbox, command: string, options?: RunCommandOptions): Promise<CommandResult> => {\n const startTime = Date.now();\n try {\n const execOptions: { env?: Record<string, string>; cwd?: string } = {};\n if (options?.env && Object.keys(options.env).length > 0) execOptions.env = options.env;\n if (options?.cwd) execOptions.cwd = options.cwd;\n const result = await sandbox.bash.exec(command, Object.keys(execOptions).length > 0 ? execOptions : undefined);\n return { stdout: result.stdout || '', stderr: result.stderr || '', exitCode: result.exitCode, durationMs: Date.now() - startTime };\n } catch (error) {\n return { stdout: '', stderr: error instanceof Error ? error.message : String(error), exitCode: 127, durationMs: Date.now() - startTime };\n }\n },\n\n getInfo: async (sandbox: JustBashSandbox): Promise<SandboxInfo> => ({\n id: sandbox.id,\n provider: 'just-bash',\n status: 'running',\n createdAt: sandbox.createdAt,\n timeout: 0,\n metadata: { type: 'local', cwd: sandbox.bash.getCwd(), python: sandbox.config.python },\n }),\n\n getUrl: async (_sandbox: JustBashSandbox, options: { port: number; protocol?: string }): Promise<string> => {\n throw new Error(`just-bash is a local sandbox without network capabilities. Cannot expose port ${options.port}.`);\n },\n\n filesystem: {\n readFile: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<string> =>\n sandbox.bash.readFile(path),\n writeFile: async (sandbox: JustBashSandbox, path: string, content: string, _runCommand): Promise<void> => {\n const parentDir = path.substring(0, path.lastIndexOf('/')) || '/';\n if (parentDir !== '/') await sandbox.bash.exec(`mkdir -p ${parentDir}`);\n await sandbox.bash.writeFile(path, content);\n },\n mkdir: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<void> => {\n const result = await sandbox.bash.exec(`mkdir -p ${path}`);\n if (result.exitCode !== 0) throw new Error(`Failed to create directory ${path}: ${result.stderr}`);\n },\n readdir: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<FileEntry[]> => {\n const result = await sandbox.bash.exec(`ls -la ${path}`);\n if (result.exitCode !== 0) throw new Error(`Failed to list directory ${path}: ${result.stderr}`);\n const entries: FileEntry[] = [];\n for (const line of result.stdout.trim().split('\\n')) {\n if (!line || line.startsWith('total')) continue;\n const parts = line.split(/\\s+/);\n if (parts.length < 9) continue;\n const name = parts.slice(8).join(' ');\n if (name === '.' || name === '..') continue;\n entries.push({ name, type: parts[0].startsWith('d') ? 'directory' as const : 'file' as const, size: parseInt(parts[4], 10) || 0, modified: new Date() });\n }\n return entries;\n },\n exists: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<boolean> => {\n const result = await sandbox.bash.exec(`test -f ${path} || test -d ${path}`);\n return result.exitCode === 0;\n },\n remove: async (sandbox: JustBashSandbox, path: string, _runCommand): Promise<void> => {\n const result = await sandbox.bash.exec(`rm -rf ${path}`);\n if (result.exitCode !== 0) throw new Error(`Failed to remove ${path}: ${result.stderr}`);\n },\n },\n\n getInstance: (sandbox: JustBashSandbox): JustBashSandbox => sandbox,\n },\n },\n});\n\nexport const justBash = (config: JustBashConfig = {}) => _provider(config);\nexport type { JustBashSandbox };\n"],"mappings":";AAMA,SAAS,YAAY;AAErB,SAAS,cAAc;AACvB,SAAS,sBAAsB;AA0B/B,IAAM,kBAAkB,oBAAI,IAA6B;AAEzD,IAAM,YAAY,eAAgD;AAAA,EAChE,MAAM;AAAA,EACN,SAAS;AAAA,IACP,SAAS;AAAA,MACP,QAAQ,OAAO,QAAwB,YAAmC;AACxE,cAAM,YAAY,aAAa,OAAO,EAAE,CAAC;AACzC,cAAM,YAAY,OAAO,UAAY,SAAiB,YAAY;AAClE,cAAM,OAAO,IAAI,KAAK;AAAA,UACpB,OAAO,OAAO;AAAA,UACd,KAAK,EAAE,GAAG,OAAO,KAAK,GAAG,SAAS,KAAK;AAAA,UACvC,KAAK,OAAO,OAAO;AAAA,UACnB,QAAQ;AAAA,UACR,IAAI,OAAO;AAAA,UACX,gBAAgB,OAAO;AAAA,UACvB,SAAS,OAAO;AAAA,QAClB,CAAC;AACD,cAAM,UAA2B,EAAE,MAAM,IAAI,WAAW,WAAW,oBAAI,KAAK,GAAG,QAAQ,EAAE,GAAG,QAAQ,QAAQ,UAAU,EAAE;AACxH,wBAAgB,IAAI,WAAW,OAAO;AACtC,eAAO,EAAE,SAAS,UAAU;AAAA,MAC9B;AAAA,MAE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AM,SAAS,MAAM,CAAC,GAAG,EAAE,KAAK,GAAG,UAAU,oBAAI,KAAK,EAAE,CAAC;AAAA,UACzJ;AACA,iBAAO;AAAA,QACT;AAAA,QACA,QAAQ,OAAO,SAA0B,MAAc,gBAAkC;AACvF,gBAAM,SAAS,MAAM,QAAQ,KAAK,KAAK,WAAW,IAAI,eAAe,IAAI,EAAE;AAC3E,iBAAO,OAAO,aAAa;AAAA,QAC7B;AAAA,QACA,QAAQ,OAAO,SAA0B,MAAc,gBAA+B;AACpF,gBAAM,SAAS,MAAM,QAAQ,KAAK,KAAK,UAAU,IAAI,EAAE;AACvD,cAAI,OAAO,aAAa,EAAG,OAAM,IAAI,MAAM,oBAAoB,IAAI,KAAK,OAAO,MAAM,EAAE;AAAA,QACzF;AAAA,MACF;AAAA,MAEA,aAAa,CAAC,YAA8C;AAAA,IAC9D;AAAA,EACF;AACF,CAAC;AAEM,IAAM,WAAW,CAAC,SAAyB,CAAC,MAAM,UAAU,MAAM;","names":[]} |
+4
-4
| { | ||
| "name": "@computesdk/just-bash", | ||
| "version": "0.4.9", | ||
| "version": "0.4.10", | ||
| "description": "just-bash provider for ComputeSDK - local sandboxed bash execution with virtual filesystem", | ||
@@ -22,4 +22,4 @@ "author": "ComputeSDK", | ||
| "nanoid": "^5.1.6", | ||
| "computesdk": "3.0.0", | ||
| "@computesdk/provider": "1.4.0" | ||
| "computesdk": "4.0.0", | ||
| "@computesdk/provider": "2.0.0" | ||
| }, | ||
@@ -38,3 +38,3 @@ "peerDependencies": { | ||
| "vitest": "^1.0.0", | ||
| "@computesdk/test-utils": "1.6.1" | ||
| "@computesdk/test-utils": "2.0.0" | ||
| }, | ||
@@ -41,0 +41,0 @@ "keywords": [ |
43406
-22.17%241
-45.1%+ Added
+ Added
- Removed
- Removed
Updated
Updated