Security protocol and hardening procedures¶
Translating natural language into executable Python and JAX code requires layered static checks, runtime confinement, and optional process or VM isolation. jaxforge (Jax Forge) enforces defense-in-depth checks across parsing, AST validation, sandbox execution, checkpoints, retry prompts, and preview approval gates.
Validation tiers¶
Inspect-first approval gates¶
Users and automated policies can inspect every generated code artifact, unified_diff, provider metadata, and validation state via preview(), dry_run=True, or approve= callbacks (auto_approve=False) before any code runs across model, training, evaluation, and data-pipeline methods.
Code parsing and AST auditor¶
Before execution, CodeParser verifies that the LLM response intent matches the requested operation, and CodeValidator parses the source into an AST and enforces structure and limits:
- Input, control-flow, and resource limits: Rejects unknown intents (fail-closed) and enforces
MAX_CODE_BYTES,MAX_CODE_LINES, andMAX_AST_NODES, while rejecting top-level side effects outside imports, function or class definitions, and call-free constant assignments. Blocks relative and wildcard*imports,finallyblocks,asyncfunctions/loops/with blocks,except*, non-allowlisted decorators, and calls in default arguments or class definitions. - Intent-scoped import allowlist:
- Core allowed root modules across all intents:
jax,flax,optax,numpy,functools,math,typing,dataclasses,equinox,grain. - Checkpoint intents (
save,load): additionally alloworbax(saveandload) andsafetensors(loadonly;save_fileis blocked duringload). - Plotting intent (
visualize_data): additionally allowmatplotlib. - Blocked submodules, names, and attributes: Rejects dangerous subpackages (
jax.profiler,numpy.ctypeslib,numpy.f2py,numpy.distutils,numpy.testing,numpy.lib,flax.io,flax.training.checkpoints,orbax.checkpoint.test_utils), dangerous builtins and names (eval,exec,compile,input,__import__,open,getattr,setattr,delattr,globals,locals,vars,type,BaseException), bareexcept:handlers, unsafe dunder and reflection attributes (__class__,__globals__,__subclasses__,__bases__,format,format_map,gi_frame,f_globals),allow_pickle=True, and unsafe NumPy file readers (fromfile,memmap,DataSource).
Runtime execution sandbox and backends¶
SandboxExecutor enforces CodeValidator.validate() even on direct calls and delegates execution to a configured ExecutionBackend:
- Controlled builtins and import guard: Exposes
SAFE_BUILTINSwrapped per execution alongside a controlled_safe_importenforcing the intent allowlist and blocking transitive stdlib module attributes (such assys,os,io,builtins, andsubprocessre-exports on allowed stdlib modules). - Read-only module proxies and confined file I/O: Exposes sandbox modules via immutable
_SafeModuleProxyinstances backed byWeakKeyDictionarystate;numpy,orbax.checkpoint,safetensors,equinox,grain, andmatplotlib.pyplot(includingFigure.savefig) validate positional and keyword path arguments againstallowed_dirsusing symlink-resolving containment (_resolve_confined_path). - Execution timeouts, resource limits, and deserialization guards:
ThreadSandboxBackendenforcestimeout_secondsusingsys.settracedeadlines and thread join bounds with an unswallowableBaseExceptiontimeout;SubprocessSandboxBackendadds OS-process isolation andresource.setrlimitmemory limits (max_memory_mb);DockerSandboxBackend,E2BSandboxBackend, andModalSandboxBackendprovide container and microVM isolation with restricted unpickling (_RestrictedUnpickler) on returned payloads. Callerruntime_argsare deep-copied per attempt so failed executions do not mutate caller objects or_current_model. - Retry prompt sanitization and privacy bounds: Redacts absolute paths, API keys, bearer headers, query credentials, and auth tokens before retry prompts, uses dynamic markdown fencing, restricts retry guidance to the target intent's allowed root modules without exposing internal AST validator implementation details, injects only structural
DatasetProfilestatistics (never raw rows by default), and bounds prompt and conversation memory sizes.
Deployment recommendations¶
For multi-tenant or untrusted public web services, configure execution_backend to "subprocess", "docker", "e2b", or "modal" with auto_approve=False, max_memory_mb, and network-egress restrictions.