Package Structure
secure-exec is split into focused packages. The umbrellasecure-exec package re-exports everything for convenience.
| Package | Contents |
|---|---|
@secure-exec/core | Shared types, utilities, bridge guest code, NodeRuntime, PythonRuntime classes |
@secure-exec/node | Node.js V8 isolate runtime driver, createNodeDriver, createNodeRuntimeDriverFactory |
@secure-exec/browser | Browser Web Worker runtime driver, createBrowserDriver, createBrowserRuntimeDriverFactory |
@secure-exec/python | Pyodide runtime driver, createPyodideRuntimeDriverFactory |
@secure-exec/typescript | Sandboxed TypeScript compiler tools |
secure-exec | Umbrella barrel — re-exports all of the above |
Runtimes
NodeRuntime
Package: @secure-exec/core (also re-exported from secure-exec)
Sandboxed JavaScript runtime using a V8 isolate.
NodeRuntimeOptions
| Option | Type | Description |
|---|---|---|
systemDriver | SystemDriver | Host capabilities (filesystem, network, permissions). Required. |
runtimeDriverFactory | NodeRuntimeDriverFactory | Creates the isolate execution environment. Required. |
memoryLimit | number | Isolate memory cap in MB. |
cpuTimeLimitMs | number | CPU time budget in ms. |
timingMitigation | "off" | "freeze" | Timing side-channel mitigation. Default "freeze". |
onStdio | StdioHook | Default console output hook. |
payloadLimits | { base64TransferBytes?: number; jsonPayloadBytes?: number } | Bridge payload size limits. |
| Method | Returns | Description |
|---|---|---|
exec(code, options?) | Promise<ExecResult> | Execute code without a return value. |
run<T>(code, filePath?) | Promise<RunResult<T>> | Execute code and return the module namespace/default export object. |
network | { fetch, dnsLookup, httpRequest } | Network access from the host side. |
dispose() | void | Release resources synchronously. |
terminate() | Promise<void> | Terminate the runtime. |
TypeScript Tools (@secure-exec/typescript)
createTypeScriptTools(options)
Creates sandboxed TypeScript project/source helpers backed by a dedicated compiler runtime.
TypeScriptToolsOptions
| Option | Type | Description |
|---|---|---|
systemDriver | SystemDriver | Compiler runtime capabilities and filesystem view. |
runtimeDriverFactory | NodeRuntimeDriverFactory | Creates the compiler sandbox runtime. |
memoryLimit | number | Compiler sandbox isolate memory cap in MB. Default 512. |
cpuTimeLimitMs | number | Compiler sandbox CPU time budget in ms. |
compilerSpecifier | string | Module specifier used to load the TypeScript compiler. Default "typescript". |
| Method | Returns | Description |
|---|---|---|
typecheckProject(options?) | Promise<TypeCheckResult> | Type-check a filesystem-backed TypeScript project using tsconfig discovery or configFilePath. |
compileProject(options?) | Promise<ProjectCompileResult> | Compile a filesystem-backed project and write emitted files through the configured filesystem like tsc. |
typecheckSource(options) | Promise<TypeCheckResult> | Type-check one TypeScript source string without mutating the filesystem. |
compileSource(options) | Promise<SourceCompileResult> | Compile one TypeScript source string and return JavaScript text. |
PythonRuntime
Package: @secure-exec/core (also re-exported from secure-exec)
Sandboxed Python runtime using Pyodide in a Worker thread.
PythonRuntimeOptions
| Option | Type | Description |
|---|---|---|
systemDriver | SystemDriver | Host capabilities. Required. |
runtimeDriverFactory | PythonRuntimeDriverFactory | Creates the Pyodide worker. Required. |
cpuTimeLimitMs | number | CPU time budget in ms. |
onStdio | StdioHook | Default console output hook. |
| Method | Returns | Description |
|---|---|---|
exec(code, options?) | Promise<ExecResult> | Execute Python code without a return value. |
run<T>(code, options?) | Promise<PythonRunResult<T>> | Execute Python code and return a value. |
dispose() | void | Release resources synchronously. |
terminate() | Promise<void> | Terminate the runtime. |
System Driver Factories
createNodeDriver(options?)
Package: @secure-exec/node (also re-exported from secure-exec)
Creates a system driver for Node.js environments.
NodeDriverOptions
| Option | Type | Description |
|---|---|---|
filesystem | VirtualFileSystem | Custom filesystem. Default: host fs with module overlay. |
moduleAccess | ModuleAccessOptions | Node modules overlay config. |
networkAdapter | NetworkAdapter | Network implementation. |
commandExecutor | CommandExecutor | Child process executor. |
permissions | Permissions | Access control rules. Deny-by-default. |
useDefaultNetwork | boolean | Enable default Node.js network adapter. |
processConfig | ProcessConfig | Process metadata (cwd, env, argv, etc.). |
osConfig | OSConfig | OS metadata (platform, arch, homedir, etc.). |
createBrowserDriver(options?)
Package: @secure-exec/browser (also re-exported from secure-exec)
Creates a system driver for browser environments. Returns a promise because OPFS initialization is async.
BrowserDriverOptions
| Option | Type | Description |
|---|---|---|
filesystem | "opfs" | "memory" | Filesystem backend. Default: "opfs". |
permissions | Permissions | Access control rules. Deny-by-default. |
useDefaultNetwork | boolean | Enable browser fetch network adapter. |
Runtime Driver Factories
createNodeRuntimeDriverFactory(options?)
Package: @secure-exec/node (also re-exported from secure-exec)
Creates a factory for Node.js V8 isolate runtime drivers.
createBrowserRuntimeDriverFactory(options?)
Package: @secure-exec/browser (also re-exported from secure-exec)
Creates a factory for browser Worker-based runtime drivers.
createPyodideRuntimeDriverFactory()
Package: @secure-exec/python (also re-exported from secure-exec)
Creates a factory for Pyodide-based Python runtime drivers.
Filesystem
createInMemoryFileSystem()
Package: @secure-exec/core (also re-exported from secure-exec)
Creates a fully in-memory filesystem backed by Maps.
createOpfsFileSystem()
Package: @secure-exec/browser (also re-exported from secure-exec)
Creates an OPFS-backed filesystem (browser only).
NodeFileSystem
Thin wrapper around Node.js fs/promises.
VirtualFileSystem interface
| Method | Returns | Description |
|---|---|---|
readFile(path) | Promise<Uint8Array> | Read file as bytes. |
readTextFile(path) | Promise<string> | Read file as text. |
readDir(path) | Promise<string[]> | List directory entries. |
readDirWithTypes(path) | Promise<DirEntry[]> | List entries with type info. |
writeFile(path, content) | Promise<void> | Write file. |
createDir(path) | Promise<void> | Create directory. |
mkdir(path) | Promise<void> | Create directory (alias). |
exists(path) | Promise<boolean> | Check if path exists. |
stat(path) | Promise<StatInfo> | Get file metadata. |
removeFile(path) | Promise<void> | Delete a file. |
removeDir(path) | Promise<void> | Delete a directory. |
rename(old, new) | Promise<void> | Rename a file or directory. |
Network
createDefaultNetworkAdapter()
Package: @secure-exec/node (also re-exported from secure-exec)
Creates a network adapter with real fetch, DNS, and HTTP support (Node.js only).
createBrowserNetworkAdapter()
Package: @secure-exec/browser (also re-exported from secure-exec)
Creates a fetch-only network adapter for browser environments. No DNS support.
NetworkAdapter interface
| Method | Returns | Description |
|---|---|---|
fetch(url, options?) | Promise<FetchResponse> | HTTP fetch. |
dnsLookup(hostname) | Promise<DnsResult> | DNS resolution. |
httpRequest(url, options?) | Promise<HttpResponse> | Low-level HTTP request. |
httpServerListen?(options) | Promise<{ address }> | Start a loopback HTTP server. |
httpServerClose?(serverId) | Promise<void> | Close a loopback HTTP server. |
Permissions
Package:@secure-exec/core (also re-exported from secure-exec)
Pre-built helpers
| Export | Description |
|---|---|
allowAll | Allow all operations. |
allowAllFs | Allow all filesystem operations. |
allowAllNetwork | Allow all network operations. |
allowAllChildProcess | Allow all child process spawning. |
allowAllEnv | Allow all environment variable access. |
Permissions type
PermissionCheck, which is either a boolean or a function (request) => boolean | Promise<boolean>.
Execution Types
ExecOptions
| Option | Type | Description |
|---|---|---|
filePath | string | Script filename for error messages. |
env | Record<string, string> | Override environment variables. |
cwd | string | Working directory. |
stdin | string | Stdin data. |
cpuTimeLimitMs | number | CPU budget override. |
timingMitigation | "off" | "freeze" | Timing mitigation override. |
onStdio | StdioHook | Per-execution stdio hook. |
ExecResult
RunResult<T>
PythonRunResult<T>
PythonRunOptions
Extends ExecOptions with:
| Option | Type | Description |
|---|---|---|
globals | string[] | Python globals to return. |
StdioHook
ProjectCompilerOptions
SourceCompilerOptions
TypeCheckResult
ProjectCompileResult
SourceCompileResult
TypeScriptDiagnostic
Configuration Types
ProcessConfig
| Field | Type | Default |
|---|---|---|
platform | string | |
arch | string | |
version | string | |
cwd | string | "/root" |
env | Record<string, string> | |
argv | string[] | |
execPath | string | |
pid | number | |
ppid | number | |
uid | number | |
gid | number | |
stdin | string | |
timingMitigation | "off" | "freeze" | |
frozenTimeMs | number |
OSConfig
| Field | Type | Default |
|---|---|---|
platform | string | |
arch | string | |
type | string | |
release | string | |
version | string | |
homedir | string | "/root" |
tmpdir | string | "/tmp" |
hostname | string |
SystemDriver
CommandExecutor interface
| Method | Returns | Description |
|---|---|---|
spawn(command, args, options?) | SpawnedProcess | Spawn a child process. |