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:
- Shape check: The code must look like a function expression
- Suspicious pattern check: Fail-fast for obviously unsandboxable patterns
Parameters
| Parameter | Type | Description |
|---|---|---|
code | string | The JavaScript code string from the LLM |
Returns
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...' }