Skip to content

Function: validateSandboxCode()

ts
function validateSandboxCode(code): GuardResult;

Defined in: packages/core/src/sandbox/SandboxGuard.ts:82

Validate LLM-provided code before sending it to the sandbox.

Performs two checks:

  1. Shape check: The code must look like a function expression
  2. Suspicious pattern check: Fail-fast for obviously unsandboxable patterns

Parameters

ParameterTypeDescription
codestringThe JavaScript code string from the LLM

Returns

GuardResult

A GuardResult indicating whether the code passed

Example

typescript
const result = validateSandboxCode('(data) => data.filter(d => d.x > 5)');
// { ok: true }

const bad = validateSandboxCode('require("fs").readFileSync("/etc/passwd")');
// { ok: false, violation: 'Code must be a function expression...' }