Skip to content

TypeScript Configuration ​

This page provides a comprehensive reference for all available configuration options, limits, and security controls when initializing a LightVM instance.

Full Configuration Example ​

The following example demonstrates how to configure all available limits, safety flags, and error options using both the builder and object patterns.

ts
import { LightVM, Capability, TimeBudget } from 'lightvm';

const vm = new LightVM({ caps: [Capability.Observe, Capability.Control] })
  .setMaxIo(100)
  .setMaxImport(3)
  .setMaxAlloc(50)
  .setMaxCall(200)
  .setMaxJump(100)
  .setMaxTicks(1_000_000)
  .setMaxStackSize(128)
  .setAllowedImports(['math', 'time', 'utils'])
  .setTimeBudget(TimeBudget.Cheap)
  .withUnsafeMode(false)
  .withNightly(false)
  .withBacktrace(false)
  .withExplain(false)
  .withHint(true)
  .withDiagnosticLinks(false);
ts
import { LightVM, Capability, TimeBudget } from 'lightvm';

const vm = new LightVM({
  caps: [Capability.Observe, Capability.Control],
  runtimeConfig: {
    nightly: false,
  },
  errorOptions: {
    backtrace: false,
    explain: false,
    hint: true,
    diagnosticLinks: false,
  },
  securityConfig: {
    maxIo: 100,
    maxImport: 3,
    maxAlloc: 50,
    maxCall: 200,
    maxJump: 100,
    maxTicks: 1_000_000,
    maxStackSize: 128,
    allowedImports: ['math', 'time', 'utils'],
    timeBudget: TimeBudget.Cheap,
    unsafeMode: false,
  },
});

Configuration Options Breakdown ​

Method / PropertyTypeDefaultDescription
capsCapability[][Capability.Observe]Specifies the active capabilities granted to the virtual machine.
setMaxIo / maxIonumber100Maximum number of I/O operations allowed during execution.
setMaxImport / maxImportnumber3Maximum number of allowed module imports.
setMaxAlloc / maxAllocnumber50Maximum number of memory allocations allowed.
setMaxCall / maxCallnumber200Maximum number of nested function calls allowed.
setMaxJump / maxJumpnumber100Maximum number of control flow jumps allowed.
setMaxTicks / maxTicksnumber1_000_000Maximum number of execution ticks before stopping to prevent infinite loops.
setMaxStackSize / maxStackSizenumber128Maximum number of items the evaluation stack can hold.
setAllowedImports / allowedImportsstring[][]Whitelist of module names that are permitted to be imported.
setTimeBudget / timeBudgetTimeBudgetTimeBudget.CheapSets the execution time budget tier limit.
withUnsafeMode / unsafeModebooleanfalseEnables or disables system-level unsafe operations.
withNightly / nightlybooleanfalseAllows the usage of experimental nightly features.
withBacktrace / backtracebooleanfalseDisplays internal backtrace details in error messages.
withExplain / explainbooleanfalseDisplays a more detailed explanatory hint in error messages.
withHint / hintbooleantrueDisplays general usage hints on error messages.
withDiagnosticLinks / diagnosticLinksbooleantrueIncludes metadata links pointing to error-code documentation.

Related Documentation

Need to check individual error codes mentioned in error messages? Visit the Error Code Reference.