| title | API Reference |
|---|---|
| description | Complete reference for all secure-exec exports. |
| Package | Contents |
|---|---|
secure-exec |
Main package — createKernel, createNodeRuntime, NodeRuntime, system drivers, filesystem, network, and permissions |
@secure-exec/core |
Kernel, types, VFS, permission helpers, shared utilities |
@secure-exec/nodejs |
Node.js runtime driver, bridge, execution driver, system driver factory |
@secure-exec/python |
Python/Pyodide runtime driver |
@secure-exec/typescript |
Sandboxed TypeScript compiler tools |
Exported from secure-exec
Creates a kernel that manages a virtual filesystem, process table, file descriptor table, pipes, PTYs, and permissions. Mount runtime drivers to execute code.
createKernel(options: KernelOptions): KernelKernelOptions
| Option | Type | Description |
|---|---|---|
filesystem |
VirtualFileSystem |
Virtual filesystem for the kernel. Required. |
permissions |
Permissions |
Access control rules. Deny-by-default. |
env |
Record<string, string> |
Environment variables. |
cwd |
string |
Working directory. Default "/root". |
maxProcesses |
number |
Maximum concurrent processes. |
Kernel methods
| Method | Returns | Description |
|---|---|---|
mount(driver) |
Promise<void> |
Mount a runtime driver. |
exec(command, options?) |
Promise<KernelExecResult> |
Execute a command string through the shell. |
spawn(command, args, options?) |
ManagedProcess |
Spawn a process directly (no shell). |
openShell(options?) |
ShellHandle |
Open an interactive shell on a PTY. |
connectTerminal(options?) |
Promise<number> |
Wire a shell to process.stdin/stdout. |
readFile(path) |
Promise<Uint8Array> |
Read a file from VFS. |
writeFile(path, content) |
Promise<void> |
Write a file to VFS. |
mkdir(path) |
Promise<void> |
Create a directory. |
readdir(path) |
Promise<string[]> |
List directory entries. |
stat(path) |
Promise<VirtualStat> |
Get file metadata. |
exists(path) |
Promise<boolean> |
Check if a path exists. |
dispose() |
Promise<void> |
Dispose the kernel and all mounted drivers. |
KernelExecResult
{ exitCode: number; stdout: string; stderr: string }Exported from secure-exec
Creates a Node.js runtime driver that can be mounted into a kernel via kernel.mount().
createNodeRuntime(options?: {
memoryLimit?: number;
moduleAccessPaths?: string[];
permissions?: Partial<Permissions>;
}): RuntimeDriver| Option | Type | Description |
|---|---|---|
memoryLimit |
number |
Memory limit in MB for each V8 isolate. Default 128. |
moduleAccessPaths |
string[] |
Host filesystem paths for module resolution. |
permissions |
Partial<Permissions> |
Bridge permissions for isolate processes. |
Exported from secure-exec
Convenience class for direct JavaScript code execution in a V8 isolate. For the kernel-first approach, use createKernel() + createNodeRuntime() instead.
new NodeRuntime(options: NodeRuntimeOptions)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. |
Methods
| 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. |
Creates sandboxed TypeScript project/source helpers backed by a dedicated compiler runtime.
createTypeScriptTools(options: TypeScriptToolsOptions)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 "/root/node_modules/typescript/lib/typescript.js". |
Methods
| 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. |
Exported from secure-exec
Creates a system driver for Node.js environments. Used with NodeRuntime.
createNodeDriver(options?: NodeDriverOptions): SystemDriverNodeDriverOptions
| 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.). |
Exported from secure-exec
Creates a fully in-memory filesystem backed by Maps.
createInMemoryFileSystem(): InMemoryFileSystemExported from secure-exec
Thin wrapper around Node.js fs/promises.
new NodeFileSystem()| 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. |
Exported from secure-exec
Creates a network adapter with real fetch, DNS, and HTTP client support (Node.js only).
createDefaultNetworkAdapter(): NetworkAdapter| 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. |
Exported from secure-exec
| 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. |
type Permissions = {
fs?: PermissionCheck<FsAccessRequest>;
network?: PermissionCheck<NetworkAccessRequest>;
childProcess?: PermissionCheck<ChildProcessAccessRequest>;
env?: PermissionCheck<EnvAccessRequest>;
};Each field accepts a PermissionCheck, which is either a boolean or a function (request) => boolean | Promise<boolean>.
| 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. |
{ code: number; errorMessage?: string }{ code: number; errorMessage?: string; exports?: T }type StdioHook = (event: { channel: "stdout" | "stderr"; message: string }) => void;{
cwd?: string;
configFilePath?: string;
}{
sourceText: string;
filePath?: string;
cwd?: string;
configFilePath?: string;
compilerOptions?: Record<string, unknown>;
}{
success: boolean;
diagnostics: TypeScriptDiagnostic[];
}{
success: boolean;
diagnostics: TypeScriptDiagnostic[];
emitSkipped: boolean;
emittedFiles: string[];
}{
success: boolean;
diagnostics: TypeScriptDiagnostic[];
outputText?: string;
sourceMapText?: string;
}{
code: number;
category: "error" | "warning" | "suggestion" | "message";
message: string;
filePath?: string;
line?: number;
column?: number;
}| 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 |
| Field | Type | Default |
|---|---|---|
platform |
string |
|
arch |
string |
|
type |
string |
|
release |
string |
|
version |
string |
|
homedir |
string |
"/root" |
tmpdir |
string |
"/tmp" |
hostname |
string |
Used internally by NodeRuntime. For the kernel-first approach, use createKernel() instead.
type SystemDriver = {
filesystem?: VirtualFileSystem;
network?: NetworkAdapter;
commandExecutor?: CommandExecutor;
permissions?: Permissions;
runtime: DriverRuntimeConfig;
};| Method | Returns | Description |
|---|---|---|
spawn(command, args, options?) |
SpawnedProcess |
Spawn a child process. |