ProDisco Run Sandbox
prodisco_runSandboxExecute and test TypeScript code in a sandboxed environment to manage Kubernetes clusters. Cache scripts for reuse, stream output, and validate with integrated tests.
Instructions
PREREQUISITE: Call searchTools first to discover correct API methods and parameters. Do NOT guess - search to find available APIs before writing code.
Execute TypeScript code in a sandboxed environment.
IMPORTANT: When executing new code, ALWAYS provide a scriptName to cache the script for future reuse. Use descriptive kebab-case names (e.g., "list-pods", "get-etcd-details", "check-node-resources"). Scripts are only cached when scriptName is provided.
BEST PRACTICE: When writing complex logic, data transformations, or code you are uncertain about, use mode: "test" first to validate your implementation with unit tests before running in production. This helps catch bugs early and ensures correctness.
MODES: • execute (default): Blocking execution, waits for completion. Params: code OR cached (required), scriptName (required for caching), timeout. • stream: Real-time output streaming. Params: code OR cached (required), scriptName (required for caching), timeout. • async: Start execution and return immediately with execution ID. Params: code OR cached (required), scriptName (required for caching), timeout. • status: Get status of async execution. Params: executionId (required), wait (optional). • cancel: Cancel a running execution. Params: executionId (required). • list: List active/recent executions. Params: states (optional), limit (optional). • test: Run unit tests with structured results. Params: tests (required), code (optional implementation to test), timeout. CRITICAL: test() and assert are pre-injected globals - do NOT import them, do NOT call test.run(). Just write: test("name", () => { assert.is(actual, expected); }); Available assertions: assert.is(a,b), assert.ok(val), assert.equal(obj1,obj2), assert.not(val), assert.throws(fn).
Sandbox provides console + process.env and restricts require() to an allowlist. ALLOWED IMPORTS:
require("@kubernetes/client-node") - Kubernetes API client
require("@prodisco/prometheus-client") - Prometheus queries & metric discovery
require("@prodisco/loki-client") - Loki LogQL querying
require("simple-statistics") - Statistics helpers
require("uvu") - Lightweight test runner for sandbox testing
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mode | No | Execution mode: "execute" (default) - blocking execution, waits for completion; "stream" - real-time output streaming; "async" - start execution and return immediately with execution ID; "status" - get status and output of an async execution; "cancel" - cancel a running execution; "list" - list active and recent executions; "test" - run tests using uvu framework with structured results | execute |
| code | No | (execute/stream/async mode) TypeScript code to execute | |
| cached | No | (execute/stream/async mode) Name of a cached script to execute (from searchTools results) | |
| scriptName | No | (execute/stream/async mode) **REQUIRED for caching**. Name for the script (e.g., "list-pods", "get-etcd-details"). Use descriptive kebab-case names. Scripts without scriptName are NOT cached. | |
| timeout | No | (execute/stream/async mode) Execution timeout in milliseconds (default: 30000, max: 120000) | |
| executionId | No | (status/cancel mode) Execution ID from async mode response | |
| wait | No | (status mode) If true, wait for completion (long-poll) | |
| outputOffset | No | (status mode) Offset in output buffer for incremental reads | |
| states | No | (list mode) Filter by execution states | |
| limit | No | (list mode) Maximum number of results | |
| includeCompletedWithinMs | No | (list mode) Include completed executions from last N milliseconds | |
| tests | No | (test mode) Test code using pre-injected test() and assert. IMPORTANT: Do NOT import test/assert, do NOT call test.run() - they are already provided. Example: test("adds numbers", () => { assert.is(add(1,2), 3); }); Available: assert.is(a,b), assert.ok(val), assert.equal(obj1,obj2), assert.not(val), assert.throws(fn) |