@enclave-vm/core 2.10.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -2059,6 +2059,7 @@ ${stackTraceHardeningCode}
2059
2059
  const hostAbortCheck = __host_abort_check__;
2060
2060
  const hostReportViolation = __host_reportViolation__;
2061
2061
  const hostConfig = __host_config__;
2062
+ const hostMemoryTrack = typeof __host_memory_track__ === 'function' ? __host_memory_track__ : function(){};
2062
2063
  const toolBridgeMode = ${JSON.stringify(toolBridgeMode)};
2063
2064
  const toolBridgeMaxPayloadBytes = ${toolBridgeMaxPayloadBytes};
2064
2065
 
@@ -2070,6 +2071,7 @@ ${stackTraceHardeningCode}
2070
2071
  try { delete globalThis.__host_abort_check__; } catch (e) { /* ignore */ }
2071
2072
  try { delete globalThis.__host_reportViolation__; } catch (e) { /* ignore */ }
2072
2073
  try { delete globalThis.__host_config__; } catch (e) { /* ignore */ }
2074
+ try { delete globalThis.__host_memory_track__; } catch (e) { /* ignore */ }
2073
2075
 
2074
2076
  // Policy violation reporter (best-effort; host decides how to handle based on security level)
2075
2077
  function __ag_reportViolation(kind) {
@@ -2639,7 +2641,7 @@ ${stackTraceHardeningCode}
2639
2641
  if (!leftIsRef && !rightIsRef) {
2640
2642
  // Track memory if enabled
2641
2643
  if (memoryLimit > 0) {
2642
- __host_memory_track__(rightLen * 2); // UTF-16 encoding
2644
+ hostMemoryTrack(rightLen * 2); // UTF-16 encoding
2643
2645
  }
2644
2646
  return left + right;
2645
2647
  }
@@ -2694,7 +2696,7 @@ ${stackTraceHardeningCode}
2694
2696
 
2695
2697
  // Track if result is a string
2696
2698
  if (typeof result === 'string' && memoryLimit > 0) {
2697
- __host_memory_track__(result.length * 2);
2699
+ hostMemoryTrack(result.length * 2);
2698
2700
  }
2699
2701
 
2700
2702
  return result;
@@ -2783,7 +2785,7 @@ ${stackTraceHardeningCode}
2783
2785
  if (consoleStats.totalBytes > maxConsoleBytes) {
2784
2786
  throw createSafeError('Console output size limit exceeded (max: ' + maxConsoleBytes + ' bytes). This limit prevents I/O flood attacks.');
2785
2787
  }
2786
- method.apply(console, arguments);
2788
+ method.call(console, output);
2787
2789
  };
2788
2790
  }
2789
2791
 
@@ -2844,9 +2846,9 @@ ${stackTraceHardeningCode}
2844
2846
  // First, inject the host memory tracking callback into innerContext
2845
2847
  // This allows the patched methods to track cumulative memory
2846
2848
  Object.defineProperty(innerContext, '__host_memory_track__', {
2847
- value: __host_memory_track__,
2849
+ value: hostMemoryTrack,
2848
2850
  writable: false,
2849
- configurable: false,
2851
+ configurable: true,
2850
2852
  enumerable: false
2851
2853
  });
2852
2854
 
@@ -2935,8 +2937,110 @@ ${stackTraceHardeningCode}
2935
2937
  // Remove dangerous globals from inner VM (AFTER memory patching)
2936
2938
  ${sanitizeContextCode}
2937
2939
 
2938
- // Freeze built-in prototypes to prevent prototype pollution
2939
- // and cut off constructor chain access for sandbox escape prevention
2940
+ // ============================================================
2941
+ // PHASE 2 HARDENING: CVE-2023-29017 Stack Overflow Escape Defense
2942
+ // ============================================================
2943
+ //
2944
+ // CRITICAL: Hardening MUST run BEFORE prototypes are frozen!
2945
+ // Otherwise Object.defineProperty calls will silently fail on frozen prototypes.
2946
+ //
2947
+ // Defense-in-depth against prototype chain escape via stack overflow errors:
2948
+ // 1. __proto__ shadowing to block prototype chain traversal
2949
+ // 2. Legacy method blocking (__lookupGetter__, etc.)
2950
+ // 3. Error constructor wrapping to secure V8-generated errors
2951
+ // 4. Then freeze all prototypes to lock in hardening
2952
+
2953
+ // HARDENING 1: Shadow __proto__ on PARENT VM error prototypes with null
2954
+ // This prevents e["__proto__"]["__proto__"] traversal attacks by making
2955
+ // __proto__ return null instead of the actual prototype chain.
2956
+ // MUST run before freeze!
2957
+ (function() {
2958
+ var errorProtos = [
2959
+ Error.prototype,
2960
+ TypeError.prototype,
2961
+ RangeError.prototype,
2962
+ SyntaxError.prototype,
2963
+ ReferenceError.prototype,
2964
+ URIError.prototype,
2965
+ EvalError.prototype
2966
+ ];
2967
+ for (var i = 0; i < errorProtos.length; i++) {
2968
+ // Shadow __proto__ with a null-returning getter
2969
+ // This blocks: error["__proto__"]["__proto__"]["__proto__"] attacks
2970
+ Object.defineProperty(errorProtos[i], '__proto__', {
2971
+ get: function() { return null; },
2972
+ set: function() { /* silently ignore */ },
2973
+ configurable: false,
2974
+ enumerable: false
2975
+ });
2976
+ }
2977
+ })();
2978
+
2979
+ // HARDENING 2: Shadow __proto__ in INNER VM error prototypes
2980
+ // MUST run before freeze!
2981
+ (function() {
2982
+ var shadowProtoCode =
2983
+ '(function() {' +
2984
+ ' var errorProtos = [' +
2985
+ ' Error.prototype,' +
2986
+ ' TypeError.prototype,' +
2987
+ ' RangeError.prototype,' +
2988
+ ' SyntaxError.prototype,' +
2989
+ ' ReferenceError.prototype,' +
2990
+ ' URIError.prototype,' +
2991
+ ' EvalError.prototype' +
2992
+ ' ];' +
2993
+ ' for (var i = 0; i < errorProtos.length; i++) {' +
2994
+ ' Object.defineProperty(errorProtos[i], "__proto__", {' +
2995
+ ' get: function() { return null; },' +
2996
+ ' set: function() {},' +
2997
+ ' configurable: false,' +
2998
+ ' enumerable: false' +
2999
+ ' });' +
3000
+ ' }' +
3001
+ '})();';
3002
+ var shadowScript = new vm.Script(shadowProtoCode);
3003
+ shadowScript.runInContext(innerContext);
3004
+ })();
3005
+
3006
+ // HARDENING 3: Block legacy prototype manipulation methods in PARENT VM
3007
+ // These deprecated methods (__lookupGetter__, __lookupSetter__, __defineGetter__, __defineSetter__)
3008
+ // can be used to bypass frozen prototype protections.
3009
+ // MUST run before freeze!
3010
+ (function() {
3011
+ var legacyMethods = ['__lookupGetter__', '__lookupSetter__', '__defineGetter__', '__defineSetter__'];
3012
+ for (var i = 0; i < legacyMethods.length; i++) {
3013
+ Object.defineProperty(Object.prototype, legacyMethods[i], {
3014
+ value: function() { return undefined; },
3015
+ writable: false,
3016
+ configurable: false,
3017
+ enumerable: false
3018
+ });
3019
+ }
3020
+ })();
3021
+
3022
+ // HARDENING 4: Block legacy prototype methods in INNER VM
3023
+ // MUST run before freeze!
3024
+ (function() {
3025
+ var blockLegacyCode =
3026
+ '(function() {' +
3027
+ ' var methods = ["__lookupGetter__", "__lookupSetter__", "__defineGetter__", "__defineSetter__"];' +
3028
+ ' for (var i = 0; i < methods.length; i++) {' +
3029
+ ' Object.defineProperty(Object.prototype, methods[i], {' +
3030
+ ' value: function() { return undefined; },' +
3031
+ ' writable: false,' +
3032
+ ' configurable: false,' +
3033
+ ' enumerable: false' +
3034
+ ' });' +
3035
+ ' }' +
3036
+ '})();';
3037
+ var blockScript = new vm.Script(blockLegacyCode);
3038
+ blockScript.runInContext(innerContext);
3039
+ })();
3040
+
3041
+ // ============================================================
3042
+ // PROTOTYPE FREEZING: Lock in hardening by freezing all prototypes
3043
+ // ============================================================
2940
3044
  //
2941
3045
  // We freeze prototypes in TWO places:
2942
3046
  // 1. PARENT VM prototypes - because SafeObject.prototype = Object.prototype uses parent's prototype
@@ -2958,6 +3062,8 @@ ${stackTraceHardeningCode}
2958
3062
  Object.freeze(RangeError.prototype);
2959
3063
  Object.freeze(SyntaxError.prototype);
2960
3064
  Object.freeze(ReferenceError.prototype);
3065
+ Object.freeze(URIError.prototype);
3066
+ Object.freeze(EvalError.prototype);
2961
3067
  Object.freeze(Promise.prototype);
2962
3068
 
2963
3069
  // Freeze INNER VM prototypes (used by literals like '', [], etc.)
@@ -2975,11 +3081,64 @@ ${stackTraceHardeningCode}
2975
3081
  'Object.freeze(RangeError.prototype);' +
2976
3082
  'Object.freeze(SyntaxError.prototype);' +
2977
3083
  'Object.freeze(ReferenceError.prototype);' +
3084
+ 'Object.freeze(URIError.prototype);' +
3085
+ 'Object.freeze(EvalError.prototype);' +
2978
3086
  'Object.freeze(Promise.prototype);';
2979
3087
  var freezeScript = new vm.Script(freezeCode);
2980
3088
  freezeScript.runInContext(innerContext);
2981
3089
  })();
2982
3090
 
3091
+ // HARDENING 5: Wrap error constructors to freeze instances
3092
+ // V8-generated errors (like stack overflow RangeError) are created internally,
3093
+ // not via the constructor. But wrapping provides defense-in-depth for any
3094
+ // errors that ARE created via constructors.
3095
+ // NOTE: This can run after freeze because it replaces global constructors, not prototype properties
3096
+ (function() {
3097
+ var wrapErrorCode =
3098
+ '(function() {' +
3099
+ ' var origError = Error;' +
3100
+ ' var origTypeError = TypeError;' +
3101
+ ' var origRangeError = RangeError;' +
3102
+ ' var origSyntaxError = SyntaxError;' +
3103
+ ' var origReferenceError = ReferenceError;' +
3104
+ ' var origEvalError = EvalError;' +
3105
+ ' var origURIError = URIError;' +
3106
+ ' function wrapErrorCtor(OrigCtor, name) {' +
3107
+ ' var WrappedCtor = function(msg) {' +
3108
+ ' var err;' +
3109
+ ' if (new.target) {' +
3110
+ ' err = new OrigCtor(msg);' +
3111
+ ' } else {' +
3112
+ ' err = OrigCtor(msg);' +
3113
+ ' }' +
3114
+ ' try { Object.freeze(err); } catch (e) {}' +
3115
+ ' return err;' +
3116
+ ' };' +
3117
+ ' WrappedCtor.prototype = OrigCtor.prototype;' +
3118
+ ' try { Object.setPrototypeOf(WrappedCtor, OrigCtor); } catch (e) {}' +
3119
+ ' try { Object.freeze(WrappedCtor); } catch (e) {}' +
3120
+ ' return WrappedCtor;' +
3121
+ ' }' +
3122
+ ' try { Error = wrapErrorCtor(origError, "Error"); } catch (e) {}' +
3123
+ ' try { TypeError = wrapErrorCtor(origTypeError, "TypeError"); } catch (e) {}' +
3124
+ ' try { RangeError = wrapErrorCtor(origRangeError, "RangeError"); } catch (e) {}' +
3125
+ ' try { SyntaxError = wrapErrorCtor(origSyntaxError, "SyntaxError"); } catch (e) {}' +
3126
+ ' try { ReferenceError = wrapErrorCtor(origReferenceError, "ReferenceError"); } catch (e) {}' +
3127
+ ' try { EvalError = wrapErrorCtor(origEvalError, "EvalError"); } catch (e) {}' +
3128
+ ' try { URIError = wrapErrorCtor(origURIError, "URIError"); } catch (e) {}' +
3129
+ '})();';
3130
+ try {
3131
+ var wrapScript = new vm.Script(wrapErrorCode);
3132
+ wrapScript.runInContext(innerContext);
3133
+ } catch (e) { /* ignore */ }
3134
+ })();
3135
+
3136
+ // NOTE: HARDENING 6 and 7 (Object.getPrototypeOf / Reflect.getPrototypeOf wrappers)
3137
+ // were removed as they break legitimate internal functionality like __safe_template.
3138
+ // The existing defenses (prototype freezing, __proto__ shadowing, error constructor
3139
+ // wrapping, codeGeneration.strings=false) provide sufficient protection against
3140
+ // the CVE-2023-29017 attack pattern.
3141
+
2983
3142
  // Inject safe runtime functions (non-writable, non-configurable)
2984
3143
  // Wrap with secure proxy to block dangerous property access
2985
3144
  var safeRuntime = {
@@ -3018,6 +3177,9 @@ ${stackTraceHardeningCode}
3018
3177
  innerRuntimeScript.runInContext(innerContext);
3019
3178
  } catch (e) { /* ignore */ }
3020
3179
 
3180
+ // Defense-in-depth: Remove host callback from inner sandbox after all scripts have captured it
3181
+ try { delete innerContext['__host_memory_track__']; } catch (e) { /* ignore */ }
3182
+
3021
3183
  // Create a safe Object that blocks dangerous STATIC methods
3022
3184
  // Prevents ATK-DATA-02 (Serialization Hijack via defineProperty)
3023
3185
  // Note: __defineGetter__ etc. are on Object.prototype (instance methods), not static
@@ -3164,6 +3326,61 @@ ${stackTraceHardeningCode}
3164
3326
  // Execute User Code
3165
3327
  // ============================================================
3166
3328
 
3329
+ // HARDENING 4: Runtime prototype verification before user code execution
3330
+ // Verifies that critical prototypes are still frozen. If any have been
3331
+ // unfrozen (which shouldn't be possible but defense-in-depth), abort.
3332
+ (function() {
3333
+ var criticalPrototypes = [
3334
+ { name: 'Object.prototype', proto: Object.prototype },
3335
+ { name: 'Array.prototype', proto: Array.prototype },
3336
+ { name: 'Function.prototype', proto: Function.prototype },
3337
+ { name: 'Error.prototype', proto: Error.prototype },
3338
+ { name: 'RangeError.prototype', proto: RangeError.prototype }
3339
+ ];
3340
+ for (var i = 0; i < criticalPrototypes.length; i++) {
3341
+ var item = criticalPrototypes[i];
3342
+ if (!Object.isFrozen(item.proto)) {
3343
+ throw new Error('SECURITY VIOLATION: ' + item.name + ' is not frozen. Aborting execution.');
3344
+ }
3345
+ }
3346
+ })();
3347
+
3348
+ // HARDENING 5: Runtime verification in INNER VM
3349
+ (function() {
3350
+ var verifyCode =
3351
+ '(function() {' +
3352
+ ' var protos = [Object.prototype, Array.prototype, Error.prototype, RangeError.prototype];' +
3353
+ ' for (var i = 0; i < protos.length; i++) {' +
3354
+ ' if (!Object.isFrozen(protos[i])) {' +
3355
+ ' throw new Error("SECURITY VIOLATION: Inner VM prototype not frozen");' +
3356
+ ' }' +
3357
+ ' }' +
3358
+ '})();';
3359
+ try {
3360
+ var verifyScript = new vm.Script(verifyCode);
3361
+ verifyScript.runInContext(innerContext);
3362
+ } catch (e) {
3363
+ if (e.message && e.message.indexOf('SECURITY VIOLATION') >= 0) {
3364
+ throw e;
3365
+ }
3366
+ /* ignore other errors */
3367
+ }
3368
+ })();
3369
+
3370
+ // Defense-in-depth: Neutralize dangerous static methods on the intrinsic Object constructor
3371
+ // in the inner VM. SafeObject only replaces the global Object variable; the REAL intrinsic
3372
+ // Object is still reachable via {}.constructor and retains getOwnPropertyDescriptors etc.
3373
+ // NOTE: Only applied to inner VM - parent VM needs these for createSecureProxy/createSafeError.
3374
+ (function() {
3375
+ var neutralizeCode =
3376
+ '(function() {' +
3377
+ ' var RealObject = Object.getPrototypeOf({}).constructor;' +
3378
+ ' var dangerous = ["getOwnPropertyDescriptors","getOwnPropertyDescriptor","defineProperty","defineProperties","setPrototypeOf"];' +
3379
+ ' for (var i = 0; i < dangerous.length; i++) { try { delete RealObject[dangerous[i]]; } catch(e) {} }' +
3380
+ '})();';
3381
+ try { var s = new vm.Script(neutralizeCode); s.runInContext(innerContext); } catch(e) { /* defense-in-depth */ }
3382
+ })();
3383
+
3167
3384
  var userCode = ${JSON.stringify(userCode)};
3168
3385
  // IMPORTANT: For stack overflow errors (RangeError: Maximum call stack size exceeded),
3169
3386
  // Node/V8 may ignore Error.prepareStackTrace when it was installed by a different Script
@@ -3681,7 +3898,7 @@ var init_double_vm_wrapper = __esm({
3681
3898
  }
3682
3899
  },
3683
3900
  writable: false,
3684
- configurable: false
3901
+ configurable: true
3685
3902
  });
3686
3903
  } else {
3687
3904
  Object.defineProperty(parentContext, "__host_memory_track__", {
@@ -3689,7 +3906,7 @@ var init_double_vm_wrapper = __esm({
3689
3906
  value: () => {
3690
3907
  },
3691
3908
  writable: false,
3692
- configurable: false
3909
+ configurable: true
3693
3910
  });
3694
3911
  }
3695
3912
  Object.defineProperty(parentContext, "console", {
@@ -4538,7 +4755,7 @@ function createSafeConsole(config, stats) {
4538
4755
  "SecurityError"
4539
4756
  );
4540
4757
  }
4541
- method(...args);
4758
+ method(output);
4542
4759
  };
4543
4760
  return {
4544
4761
  log: wrap(console.log.bind(console)),
@@ -4673,7 +4890,7 @@ function sanitizeVmContext(context, securityLevel) {
4673
4890
  enumerable: true
4674
4891
  });
4675
4892
  }
4676
- var vm3, SENSITIVE_STACK_PATTERNS2, STACK_TRACE_HARDENING_CODE, STACK_TRACE_HARDENING_SCRIPT, CODE_GENERATION_VIOLATION_DETECTOR_CODE, CODE_GENERATION_VIOLATION_DETECTOR_SCRIPT, PROTECTED_PREFIXES, DANGEROUS_OBJECT_STATIC_METHODS, NODEJS_24_DANGEROUS_GLOBALS2, VmAdapter;
4893
+ var vm3, SENSITIVE_STACK_PATTERNS2, STACK_TRACE_HARDENING_CODE, STACK_TRACE_HARDENING_SCRIPT, CODE_GENERATION_VIOLATION_DETECTOR_CODE, CODE_GENERATION_VIOLATION_DETECTOR_SCRIPT, INTRINSIC_OBJECT_NEUTRALIZATION_CODE, INTRINSIC_OBJECT_NEUTRALIZATION_SCRIPT, PROTECTED_PREFIXES, DANGEROUS_OBJECT_STATIC_METHODS, NODEJS_24_DANGEROUS_GLOBALS2, VmAdapter;
4677
4894
  var init_vm_adapter = __esm({
4678
4895
  "libs/core/src/adapters/vm-adapter.ts"() {
4679
4896
  "use strict";
@@ -4957,6 +5174,22 @@ var init_vm_adapter = __esm({
4957
5174
  })();
4958
5175
  `.trim();
4959
5176
  CODE_GENERATION_VIOLATION_DETECTOR_SCRIPT = new vm3.Script(CODE_GENERATION_VIOLATION_DETECTOR_CODE);
5177
+ INTRINSIC_OBJECT_NEUTRALIZATION_CODE = `
5178
+ (function() {
5179
+ var RealObject = Object.getPrototypeOf({}).constructor;
5180
+ var dangerous = [
5181
+ 'getOwnPropertyDescriptors',
5182
+ 'getOwnPropertyDescriptor',
5183
+ 'defineProperty',
5184
+ 'defineProperties',
5185
+ 'setPrototypeOf'
5186
+ ];
5187
+ for (var i = 0; i < dangerous.length; i++) {
5188
+ try { delete RealObject[dangerous[i]]; } catch (e) {}
5189
+ }
5190
+ })();
5191
+ `;
5192
+ INTRINSIC_OBJECT_NEUTRALIZATION_SCRIPT = new vm3.Script(INTRINSIC_OBJECT_NEUTRALIZATION_CODE);
4960
5193
  PROTECTED_PREFIXES = ["__safe_", "__ag_"];
4961
5194
  DANGEROUS_OBJECT_STATIC_METHODS = [
4962
5195
  "defineProperty",
@@ -5091,7 +5324,7 @@ var init_vm_adapter = __esm({
5091
5324
  memoryTracker.track(bytes);
5092
5325
  },
5093
5326
  writable: false,
5094
- configurable: false,
5327
+ configurable: true,
5095
5328
  enumerable: false
5096
5329
  });
5097
5330
  const patchScript = new vm3.Script(`
@@ -5198,6 +5431,10 @@ var init_vm_adapter = __esm({
5198
5431
  })();
5199
5432
  `);
5200
5433
  patchScript.runInContext(baseSandbox);
5434
+ try {
5435
+ delete baseSandbox["__host_memory_track__"];
5436
+ } catch {
5437
+ }
5201
5438
  }
5202
5439
  const shouldHardenStacks = config.sanitizeStackTraces ?? true;
5203
5440
  if (shouldHardenStacks) {
@@ -5368,17 +5605,16 @@ var init_vm_adapter = __esm({
5368
5605
  ),
5369
5606
  writable: false,
5370
5607
  configurable: false,
5371
- enumerable: true
5608
+ enumerable: false
5372
5609
  });
5373
5610
  }
5611
+ try {
5612
+ INTRINSIC_OBJECT_NEUTRALIZATION_SCRIPT.runInContext(baseSandbox);
5613
+ } catch {
5614
+ }
5374
5615
  const _protectedSandbox = createProtectedSandbox(baseSandbox);
5375
5616
  this.context = baseSandbox;
5376
- const wrappedCode = `
5377
- (async () => {
5378
- ${code}
5379
- return typeof __ag_main === 'function' ? await __ag_main() : undefined;
5380
- })();
5381
- `;
5617
+ const wrappedCode = "(async () => {\n" + code + '\nreturn typeof __ag_main === "function" ? await __ag_main() : undefined;\n})();';
5382
5618
  const script = new vm3.Script(wrappedCode, {
5383
5619
  filename: "agentscript.js"
5384
5620
  });
@@ -6598,6 +6834,8 @@ var init_worker_pool_adapter = __esm({
6598
6834
  rateLimiter;
6599
6835
  disposed = false;
6600
6836
  initialized = false;
6837
+ // Bound event handler for proper cleanup
6838
+ boundMemoryExceededHandler = this.handleMemoryExceeded.bind(this);
6601
6839
  // Metrics
6602
6840
  _totalExecutions = 0;
6603
6841
  _successfulExecutions = 0;
@@ -6620,7 +6858,7 @@ var init_worker_pool_adapter = __esm({
6620
6858
  this.slots
6621
6859
  );
6622
6860
  this.rateLimiter = createRateLimiter(this.config.maxMessagesPerSecond);
6623
- this.memoryMonitor.on("memoryExceeded", this.handleMemoryExceeded.bind(this));
6861
+ this.memoryMonitor.on("memoryExceeded", this.boundMemoryExceededHandler);
6624
6862
  }
6625
6863
  /**
6626
6864
  * Initialize the worker pool
@@ -6685,6 +6923,7 @@ var init_worker_pool_adapter = __esm({
6685
6923
  return;
6686
6924
  }
6687
6925
  this.disposed = true;
6926
+ this.memoryMonitor.off("memoryExceeded", this.boundMemoryExceededHandler);
6688
6927
  this.memoryMonitor.stop();
6689
6928
  this.executionQueue.clear();
6690
6929
  const terminatePromises = [];
@@ -9873,6 +10112,7 @@ var Enclave = class {
9873
10112
  referenceConfig;
9874
10113
  scoringGate;
9875
10114
  doubleVmConfig;
10115
+ customGlobalNames;
9876
10116
  adapter;
9877
10117
  constructor(options = {}) {
9878
10118
  this.securityLevel = options.securityLevel ?? DEFAULT_SECURITY_LEVEL;
@@ -9944,8 +10184,8 @@ var Enclave = class {
9944
10184
  secureProxyConfig: securityConfig.secureProxyConfig,
9945
10185
  globals: initialGlobals
9946
10186
  };
9947
- const customGlobalNames = Object.keys(initialGlobals);
9948
- const customAllowedGlobals = customGlobalNames.flatMap((name) => [name, `__safe_${name}`]);
10187
+ this.customGlobalNames = Object.keys(initialGlobals);
10188
+ const customAllowedGlobals = this.customGlobalNames.flatMap((name) => [name, `__safe_${name}`]);
9949
10189
  this.validator = this.createValidator(presetName, customAllowedGlobals);
9950
10190
  this.validateCode = options.validate !== false;
9951
10191
  this.transformCode = options.transform !== false;
@@ -10009,7 +10249,9 @@ var Enclave = class {
10009
10249
  transformedCode = (0, import_ast4.transformAgentScript)(code, {
10010
10250
  wrapInMain: needsWrapping,
10011
10251
  transformCallTool: true,
10012
- transformLoops: true
10252
+ transformLoops: true,
10253
+ // Pass custom global names so they aren't transformed to __safe_ prefix
10254
+ additionalIdentifiers: this.customGlobalNames
10013
10255
  });
10014
10256
  }
10015
10257
  if (this.validateCode) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enclave-vm/core",
3
- "version": "2.10.0",
3
+ "version": "2.11.0",
4
4
  "description": "Sandbox runtime for secure JavaScript code execution",
5
5
  "author": "AgentFront <info@agentfront.dev>",
6
6
  "homepage": "https://github.com/agentfront/enclave",
@@ -37,13 +37,13 @@
37
37
  }
38
38
  },
39
39
  "dependencies": {
40
- "@babel/standalone": "^7.28.6",
41
- "@enclave-vm/types": "2.10.0",
42
- "@enclave-vm/ast": "2.10.0",
40
+ "@babel/standalone": "^7.29.0",
41
+ "@enclave-vm/types": "2.11.0",
42
+ "@enclave-vm/ast": "2.11.0",
43
43
  "acorn": "8.15.0",
44
44
  "acorn-walk": "8.3.4",
45
45
  "astring": "1.9.0",
46
- "zod": "^4.1.13"
46
+ "zod": "^4.3.6"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "@huggingface/transformers": "^3.2.2",
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@enclave-vm/core",
3
+ "version": "2.11.0",
4
+ "description": "Sandbox runtime for secure JavaScript code execution",
5
+ "author": "AgentFront <info@agentfront.dev>",
6
+ "homepage": "https://github.com/agentfront/enclave",
7
+ "license": "Apache-2.0",
8
+ "keywords": [
9
+ "sandbox",
10
+ "vm",
11
+ "enclave",
12
+ "enclave-vm",
13
+ "agentscript",
14
+ "llm",
15
+ "javascript",
16
+ "execution",
17
+ "security",
18
+ "ast-guard"
19
+ ],
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/agentfront/enclave.git"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/agentfront/enclave/issues"
26
+ },
27
+ "main": "./dist/index.js",
28
+ "module": "./dist/esm/index.mjs",
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ "./package.json": "./package.json",
32
+ ".": {
33
+ "development": "./src/index.ts",
34
+ "types": "./dist/index.d.ts",
35
+ "import": "./dist/esm/index.mjs",
36
+ "require": "./dist/index.js",
37
+ "default": "./dist/index.js"
38
+ }
39
+ },
40
+ "dependencies": {
41
+ "@babel/standalone": "^7.29.0",
42
+ "@enclave-vm/types": "2.11.0",
43
+ "@enclave-vm/ast": "2.11.0",
44
+ "acorn": "8.15.0",
45
+ "acorn-walk": "8.3.4",
46
+ "astring": "1.9.0",
47
+ "zod": "^4.3.6"
48
+ },
49
+ "peerDependencies": {
50
+ "@huggingface/transformers": "^3.2.2",
51
+ "vectoriadb": "^2.1.3"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "@huggingface/transformers": {
55
+ "optional": true
56
+ },
57
+ "vectoriadb": {
58
+ "optional": true
59
+ }
60
+ }
61
+ }