@secure-exec/core 0.0.0-main.bccb3a2

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.
Files changed (271) hide show
  1. package/README.md +7 -0
  2. package/commands/[ +0 -0
  3. package/commands/_stubs +0 -0
  4. package/commands/arch +0 -0
  5. package/commands/awk +0 -0
  6. package/commands/b2sum +0 -0
  7. package/commands/base32 +0 -0
  8. package/commands/base64 +0 -0
  9. package/commands/basename +0 -0
  10. package/commands/basenc +0 -0
  11. package/commands/bash +0 -0
  12. package/commands/cat +0 -0
  13. package/commands/chcon +0 -0
  14. package/commands/chgrp +0 -0
  15. package/commands/chmod +0 -0
  16. package/commands/chown +0 -0
  17. package/commands/chroot +0 -0
  18. package/commands/cksum +0 -0
  19. package/commands/codex +0 -0
  20. package/commands/codex-exec +0 -0
  21. package/commands/column +0 -0
  22. package/commands/comm +0 -0
  23. package/commands/cp +0 -0
  24. package/commands/curl +0 -0
  25. package/commands/cut +0 -0
  26. package/commands/date +0 -0
  27. package/commands/dd +0 -0
  28. package/commands/df +0 -0
  29. package/commands/diff +0 -0
  30. package/commands/dir +0 -0
  31. package/commands/dircolors +0 -0
  32. package/commands/dirname +0 -0
  33. package/commands/du +0 -0
  34. package/commands/echo +0 -0
  35. package/commands/egrep +0 -0
  36. package/commands/env +0 -0
  37. package/commands/expand +0 -0
  38. package/commands/expr +0 -0
  39. package/commands/factor +0 -0
  40. package/commands/false +0 -0
  41. package/commands/fd +0 -0
  42. package/commands/fgrep +0 -0
  43. package/commands/file +0 -0
  44. package/commands/find +0 -0
  45. package/commands/fmt +0 -0
  46. package/commands/fold +0 -0
  47. package/commands/git +0 -0
  48. package/commands/grep +0 -0
  49. package/commands/groups +0 -0
  50. package/commands/gunzip +0 -0
  51. package/commands/gzip +0 -0
  52. package/commands/head +0 -0
  53. package/commands/hostid +0 -0
  54. package/commands/hostname +0 -0
  55. package/commands/http-test +0 -0
  56. package/commands/id +0 -0
  57. package/commands/install +0 -0
  58. package/commands/join +0 -0
  59. package/commands/jq +0 -0
  60. package/commands/kill +0 -0
  61. package/commands/link +0 -0
  62. package/commands/ln +0 -0
  63. package/commands/logname +0 -0
  64. package/commands/ls +0 -0
  65. package/commands/md5sum +0 -0
  66. package/commands/mkdir +0 -0
  67. package/commands/mkfifo +0 -0
  68. package/commands/mknod +0 -0
  69. package/commands/mktemp +0 -0
  70. package/commands/more +0 -0
  71. package/commands/mv +0 -0
  72. package/commands/nice +0 -0
  73. package/commands/nl +0 -0
  74. package/commands/nohup +0 -0
  75. package/commands/nproc +0 -0
  76. package/commands/numfmt +0 -0
  77. package/commands/od +0 -0
  78. package/commands/paste +0 -0
  79. package/commands/pathchk +0 -0
  80. package/commands/pinky +0 -0
  81. package/commands/printenv +0 -0
  82. package/commands/printf +0 -0
  83. package/commands/ptx +0 -0
  84. package/commands/pwd +0 -0
  85. package/commands/readlink +0 -0
  86. package/commands/realpath +0 -0
  87. package/commands/rev +0 -0
  88. package/commands/rg +0 -0
  89. package/commands/rm +0 -0
  90. package/commands/rmdir +0 -0
  91. package/commands/runcon +0 -0
  92. package/commands/sed +0 -0
  93. package/commands/seq +0 -0
  94. package/commands/sh +0 -0
  95. package/commands/sha1sum +0 -0
  96. package/commands/sha224sum +0 -0
  97. package/commands/sha256sum +0 -0
  98. package/commands/sha384sum +0 -0
  99. package/commands/sha512sum +0 -0
  100. package/commands/shred +0 -0
  101. package/commands/shuf +0 -0
  102. package/commands/sleep +0 -0
  103. package/commands/sort +0 -0
  104. package/commands/spawn-test-host +0 -0
  105. package/commands/split +0 -0
  106. package/commands/stat +0 -0
  107. package/commands/stdbuf +0 -0
  108. package/commands/strings +0 -0
  109. package/commands/stty +0 -0
  110. package/commands/sum +0 -0
  111. package/commands/sync +0 -0
  112. package/commands/tac +0 -0
  113. package/commands/tail +0 -0
  114. package/commands/tar +0 -0
  115. package/commands/tee +0 -0
  116. package/commands/test +0 -0
  117. package/commands/timeout +0 -0
  118. package/commands/touch +0 -0
  119. package/commands/tr +0 -0
  120. package/commands/tree +0 -0
  121. package/commands/true +0 -0
  122. package/commands/truncate +0 -0
  123. package/commands/tsort +0 -0
  124. package/commands/tty +0 -0
  125. package/commands/uname +0 -0
  126. package/commands/unexpand +0 -0
  127. package/commands/uniq +0 -0
  128. package/commands/unlink +0 -0
  129. package/commands/uptime +0 -0
  130. package/commands/users +0 -0
  131. package/commands/vdir +0 -0
  132. package/commands/wc +0 -0
  133. package/commands/which +0 -0
  134. package/commands/who +0 -0
  135. package/commands/whoami +0 -0
  136. package/commands/xargs +0 -0
  137. package/commands/xu +0 -0
  138. package/commands/yes +0 -0
  139. package/commands/yq +0 -0
  140. package/commands/zcat +0 -0
  141. package/dist/binary.d.ts +4 -0
  142. package/dist/binary.js +25 -0
  143. package/dist/bytes.d.ts +2 -0
  144. package/dist/bytes.js +6 -0
  145. package/dist/callbacks.d.ts +41 -0
  146. package/dist/callbacks.js +94 -0
  147. package/dist/cargo.d.ts +2 -0
  148. package/dist/cargo.js +142 -0
  149. package/dist/correlation.d.ts +10 -0
  150. package/dist/correlation.js +49 -0
  151. package/dist/descriptors.d.ts +34 -0
  152. package/dist/descriptors.js +37 -0
  153. package/dist/event-buffer.d.ts +90 -0
  154. package/dist/event-buffer.js +313 -0
  155. package/dist/ext.d.ts +7 -0
  156. package/dist/ext.js +13 -0
  157. package/dist/filesystem.d.ts +41 -0
  158. package/dist/filesystem.js +70 -0
  159. package/dist/frame-payload-codec.d.ts +8 -0
  160. package/dist/frame-payload-codec.js +14 -0
  161. package/dist/frame-rpc.d.ts +38 -0
  162. package/dist/frame-rpc.js +73 -0
  163. package/dist/frame-stream.d.ts +27 -0
  164. package/dist/frame-stream.js +99 -0
  165. package/dist/framing.d.ts +7 -0
  166. package/dist/framing.js +22 -0
  167. package/dist/generated/AcpLimitsConfig.d.ts +4 -0
  168. package/dist/generated/AcpLimitsConfig.js +2 -0
  169. package/dist/generated/CreateVmConfig.d.ts +19 -0
  170. package/dist/generated/CreateVmConfig.js +1 -0
  171. package/dist/generated/FsPermissionRule.d.ts +6 -0
  172. package/dist/generated/FsPermissionRule.js +1 -0
  173. package/dist/generated/FsPermissionRuleSet.d.ts +6 -0
  174. package/dist/generated/FsPermissionRuleSet.js +1 -0
  175. package/dist/generated/FsPermissionScope.d.ts +3 -0
  176. package/dist/generated/FsPermissionScope.js +1 -0
  177. package/dist/generated/HttpLimitsConfig.d.ts +3 -0
  178. package/dist/generated/HttpLimitsConfig.js +2 -0
  179. package/dist/generated/JsModuleResolution.d.ts +1 -0
  180. package/dist/generated/JsModuleResolution.js +2 -0
  181. package/dist/generated/JsRuntimeConfig.d.ts +26 -0
  182. package/dist/generated/JsRuntimeConfig.js +1 -0
  183. package/dist/generated/JsRuntimeLimitsConfig.d.ts +8 -0
  184. package/dist/generated/JsRuntimeLimitsConfig.js +2 -0
  185. package/dist/generated/JsRuntimePlatform.d.ts +1 -0
  186. package/dist/generated/JsRuntimePlatform.js +2 -0
  187. package/dist/generated/MountPluginDescriptor.d.ts +4 -0
  188. package/dist/generated/MountPluginDescriptor.js +2 -0
  189. package/dist/generated/NativeRootFilesystemConfig.d.ts +5 -0
  190. package/dist/generated/NativeRootFilesystemConfig.js +1 -0
  191. package/dist/generated/PatternPermissionRule.d.ts +6 -0
  192. package/dist/generated/PatternPermissionRule.js +1 -0
  193. package/dist/generated/PatternPermissionRuleSet.d.ts +6 -0
  194. package/dist/generated/PatternPermissionRuleSet.js +1 -0
  195. package/dist/generated/PatternPermissionScope.d.ts +3 -0
  196. package/dist/generated/PatternPermissionScope.js +1 -0
  197. package/dist/generated/PermissionMode.d.ts +1 -0
  198. package/dist/generated/PermissionMode.js +2 -0
  199. package/dist/generated/PermissionsPolicy.d.ts +10 -0
  200. package/dist/generated/PermissionsPolicy.js +1 -0
  201. package/dist/generated/PluginLimitsConfig.d.ts +4 -0
  202. package/dist/generated/PluginLimitsConfig.js +2 -0
  203. package/dist/generated/PythonLimitsConfig.d.ts +6 -0
  204. package/dist/generated/PythonLimitsConfig.js +2 -0
  205. package/dist/generated/ResourceLimitsConfig.d.ts +22 -0
  206. package/dist/generated/ResourceLimitsConfig.js +2 -0
  207. package/dist/generated/RootFilesystemConfig.d.ts +9 -0
  208. package/dist/generated/RootFilesystemConfig.js +1 -0
  209. package/dist/generated/RootFilesystemEntry.d.ts +13 -0
  210. package/dist/generated/RootFilesystemEntry.js +1 -0
  211. package/dist/generated/RootFilesystemEntryEncoding.d.ts +1 -0
  212. package/dist/generated/RootFilesystemEntryEncoding.js +2 -0
  213. package/dist/generated/RootFilesystemEntryKind.d.ts +1 -0
  214. package/dist/generated/RootFilesystemEntryKind.js +2 -0
  215. package/dist/generated/RootFilesystemLowerDescriptor.d.ts +7 -0
  216. package/dist/generated/RootFilesystemLowerDescriptor.js +1 -0
  217. package/dist/generated/RootFilesystemMode.d.ts +1 -0
  218. package/dist/generated/RootFilesystemMode.js +2 -0
  219. package/dist/generated/ToolLimitsConfig.d.ts +10 -0
  220. package/dist/generated/ToolLimitsConfig.js +2 -0
  221. package/dist/generated/VmDnsConfig.d.ts +6 -0
  222. package/dist/generated/VmDnsConfig.js +2 -0
  223. package/dist/generated/VmLimitsConfig.d.ts +18 -0
  224. package/dist/generated/VmLimitsConfig.js +1 -0
  225. package/dist/generated/VmListenPolicyConfig.d.ts +5 -0
  226. package/dist/generated/VmListenPolicyConfig.js +2 -0
  227. package/dist/generated/WasmLimitsConfig.d.ts +5 -0
  228. package/dist/generated/WasmLimitsConfig.js +2 -0
  229. package/dist/generated-protocol.d.ts +1037 -0
  230. package/dist/generated-protocol.js +2887 -0
  231. package/dist/index.d.ts +26 -0
  232. package/dist/index.js +25 -0
  233. package/dist/json.d.ts +2 -0
  234. package/dist/json.js +20 -0
  235. package/dist/kernel-proxy.d.ts +151 -0
  236. package/dist/kernel-proxy.js +1737 -0
  237. package/dist/native-client.d.ts +41 -0
  238. package/dist/native-client.js +124 -0
  239. package/dist/node-runtime.d.ts +516 -0
  240. package/dist/node-runtime.js +794 -0
  241. package/dist/numbers.d.ts +1 -0
  242. package/dist/numbers.js +8 -0
  243. package/dist/ownership.d.ts +18 -0
  244. package/dist/ownership.js +77 -0
  245. package/dist/permissions.d.ts +29 -0
  246. package/dist/permissions.js +68 -0
  247. package/dist/process.d.ts +35 -0
  248. package/dist/process.js +125 -0
  249. package/dist/protocol-client.d.ts +46 -0
  250. package/dist/protocol-client.js +180 -0
  251. package/dist/protocol-frames.d.ts +68 -0
  252. package/dist/protocol-frames.js +139 -0
  253. package/dist/protocol-maps.d.ts +28 -0
  254. package/dist/protocol-maps.js +217 -0
  255. package/dist/protocol-schema.d.ts +10 -0
  256. package/dist/protocol-schema.js +11 -0
  257. package/dist/request-payloads.d.ts +137 -0
  258. package/dist/request-payloads.js +210 -0
  259. package/dist/response-payloads.d.ts +107 -0
  260. package/dist/response-payloads.js +161 -0
  261. package/dist/sidecar-client.d.ts +242 -0
  262. package/dist/sidecar-client.js +797 -0
  263. package/dist/state.d.ts +40 -0
  264. package/dist/state.js +44 -0
  265. package/dist/test-runtime.d.ts +534 -0
  266. package/dist/test-runtime.js +2146 -0
  267. package/dist/vm-config.d.ts +31 -0
  268. package/dist/vm-config.js +1 -0
  269. package/fixtures/alpine-defaults.json +520 -0
  270. package/fixtures/base-filesystem.json +528 -0
  271. package/package.json +197 -0
@@ -0,0 +1,40 @@
1
+ import * as protocol from "./generated-protocol.js";
2
+ export interface LiveGuestFilesystemStat {
3
+ mode: number;
4
+ size: number;
5
+ blocks: number;
6
+ dev: number;
7
+ rdev: number;
8
+ is_directory: boolean;
9
+ is_symbolic_link: boolean;
10
+ atime_ms: number;
11
+ mtime_ms: number;
12
+ ctime_ms: number;
13
+ birthtime_ms: number;
14
+ ino: number;
15
+ nlink: number;
16
+ uid: number;
17
+ gid: number;
18
+ }
19
+ export interface LiveSocketStateEntry {
20
+ process_id: string;
21
+ host?: string;
22
+ port?: number;
23
+ path?: string;
24
+ }
25
+ export interface LiveProcessSnapshotEntry {
26
+ process_id: string;
27
+ pid: number;
28
+ ppid: number;
29
+ pgid: number;
30
+ sid: number;
31
+ driver: string;
32
+ command: string;
33
+ args?: string[];
34
+ cwd: string;
35
+ status: "running" | "exited" | "stopped";
36
+ exit_code?: number;
37
+ }
38
+ export declare function fromGeneratedGuestFilesystemStat(stat: protocol.GuestFilesystemStat): LiveGuestFilesystemStat;
39
+ export declare function fromGeneratedSocketStateEntry(entry: protocol.SocketStateEntry): LiveSocketStateEntry;
40
+ export declare function fromGeneratedProcessSnapshotEntry(entry: protocol.ProcessSnapshotEntry): LiveProcessSnapshotEntry;
package/dist/state.js ADDED
@@ -0,0 +1,44 @@
1
+ import { bigIntToSafeNumber } from "./numbers.js";
2
+ import { fromGeneratedProcessSnapshotStatus } from "./protocol-maps.js";
3
+ export function fromGeneratedGuestFilesystemStat(stat) {
4
+ return {
5
+ mode: stat.mode,
6
+ size: bigIntToSafeNumber(stat.size, "guest filesystem stat size"),
7
+ blocks: bigIntToSafeNumber(stat.blocks, "guest filesystem stat blocks"),
8
+ dev: bigIntToSafeNumber(stat.dev, "guest filesystem stat dev"),
9
+ rdev: bigIntToSafeNumber(stat.rdev, "guest filesystem stat rdev"),
10
+ is_directory: stat.isDirectory,
11
+ is_symbolic_link: stat.isSymbolicLink,
12
+ atime_ms: bigIntToSafeNumber(stat.atimeMs, "guest filesystem stat atime"),
13
+ mtime_ms: bigIntToSafeNumber(stat.mtimeMs, "guest filesystem stat mtime"),
14
+ ctime_ms: bigIntToSafeNumber(stat.ctimeMs, "guest filesystem stat ctime"),
15
+ birthtime_ms: bigIntToSafeNumber(stat.birthtimeMs, "guest filesystem stat birthtime"),
16
+ ino: bigIntToSafeNumber(stat.ino, "guest filesystem stat ino"),
17
+ nlink: bigIntToSafeNumber(stat.nlink, "guest filesystem stat nlink"),
18
+ uid: stat.uid,
19
+ gid: stat.gid,
20
+ };
21
+ }
22
+ export function fromGeneratedSocketStateEntry(entry) {
23
+ return {
24
+ process_id: entry.processId,
25
+ ...(entry.host !== null ? { host: entry.host } : {}),
26
+ ...(entry.port !== null ? { port: entry.port } : {}),
27
+ ...(entry.path !== null ? { path: entry.path } : {}),
28
+ };
29
+ }
30
+ export function fromGeneratedProcessSnapshotEntry(entry) {
31
+ return {
32
+ process_id: entry.processId,
33
+ pid: entry.pid,
34
+ ppid: entry.ppid,
35
+ pgid: entry.pgid,
36
+ sid: entry.sid,
37
+ driver: entry.driver,
38
+ command: entry.command,
39
+ args: [...entry.args],
40
+ cwd: entry.cwd,
41
+ status: fromGeneratedProcessSnapshotStatus(entry.status),
42
+ ...(entry.exitCode !== null ? { exit_code: entry.exitCode } : {}),
43
+ };
44
+ }
@@ -0,0 +1,534 @@
1
+ import { Sidecar } from "./kernel-proxy.js";
2
+ export declare const AF_INET = 2;
3
+ export declare const AF_UNIX = 1;
4
+ export declare const SOCK_STREAM = 1;
5
+ export declare const SOCK_DGRAM = 2;
6
+ export declare const SIGTERM = 15;
7
+ export type KernelBootTimingPhase = "filesystem_snapshot" | "sidecar_spawn" | "session_open" | "vm_create" | "vm_ready" | "vm_configure";
8
+ export interface KernelBootTiming {
9
+ phase: KernelBootTimingPhase;
10
+ durationMs: number;
11
+ }
12
+ export type StdioChannel = "stdout" | "stderr";
13
+ export type TimingMitigation = "off" | "freeze";
14
+ export type PermissionMode = "allow" | "deny";
15
+ export type PermissionDecision = PermissionMode;
16
+ export interface VirtualDirEntry {
17
+ name: string;
18
+ isDirectory: boolean;
19
+ isSymbolicLink?: boolean;
20
+ }
21
+ export interface VirtualStat {
22
+ mode: number;
23
+ size: number;
24
+ blocks: number;
25
+ dev: number;
26
+ rdev: number;
27
+ isDirectory: boolean;
28
+ isSymbolicLink: boolean;
29
+ atimeMs: number;
30
+ mtimeMs: number;
31
+ ctimeMs: number;
32
+ birthtimeMs: number;
33
+ ino: number;
34
+ nlink: number;
35
+ uid: number;
36
+ gid: number;
37
+ }
38
+ export interface VirtualFileSystem {
39
+ readFile(path: string): Promise<Uint8Array>;
40
+ readTextFile(path: string): Promise<string>;
41
+ readDir(path: string): Promise<string[]>;
42
+ readDirWithTypes(path: string): Promise<VirtualDirEntry[]>;
43
+ writeFile(path: string, content: string | Uint8Array): Promise<void>;
44
+ createDir(path: string): Promise<void>;
45
+ mkdir(path: string, options?: {
46
+ recursive?: boolean;
47
+ }): Promise<void>;
48
+ exists(path: string): Promise<boolean>;
49
+ stat(path: string): Promise<VirtualStat>;
50
+ removeFile(path: string): Promise<void>;
51
+ removeDir(path: string): Promise<void>;
52
+ rename(oldPath: string, newPath: string): Promise<void>;
53
+ realpath(path: string): Promise<string>;
54
+ symlink(target: string, linkPath: string): Promise<void>;
55
+ readlink(path: string): Promise<string>;
56
+ lstat(path: string): Promise<VirtualStat>;
57
+ link(oldPath: string, newPath: string): Promise<void>;
58
+ chmod(path: string, mode: number): Promise<void>;
59
+ chown(path: string, uid: number, gid: number): Promise<void>;
60
+ utimes(path: string, atime: number, mtime: number): Promise<void>;
61
+ truncate(path: string, length: number): Promise<void>;
62
+ pread(path: string, offset: number, length: number): Promise<Uint8Array>;
63
+ pwrite(path: string, offset: number, data: Uint8Array): Promise<void>;
64
+ }
65
+ export interface NetworkAccessRequest {
66
+ url?: string;
67
+ host?: string;
68
+ port?: number;
69
+ protocol?: string;
70
+ }
71
+ export interface FsPermissionRule {
72
+ mode: PermissionMode;
73
+ operations?: string[];
74
+ paths?: string[];
75
+ }
76
+ export interface PatternPermissionRule {
77
+ mode: PermissionMode;
78
+ operations?: string[];
79
+ patterns?: string[];
80
+ }
81
+ export interface RulePermissions<TRule> {
82
+ default?: PermissionMode;
83
+ rules: TRule[];
84
+ }
85
+ export type FsPermissions = PermissionMode | RulePermissions<FsPermissionRule>;
86
+ export type NetworkPermissions = PermissionMode | RulePermissions<PatternPermissionRule>;
87
+ export type ChildProcessPermissions = PermissionMode | RulePermissions<PatternPermissionRule>;
88
+ export type ProcessPermissions = PermissionMode | RulePermissions<PatternPermissionRule>;
89
+ export type EnvPermissions = PermissionMode | RulePermissions<PatternPermissionRule>;
90
+ export type ToolPermissions = PermissionMode | RulePermissions<PatternPermissionRule>;
91
+ export interface ProcessInfo {
92
+ pid: number;
93
+ ppid: number;
94
+ pgid: number;
95
+ sid: number;
96
+ driver: string;
97
+ command: string;
98
+ args: string[];
99
+ cwd: string;
100
+ status: "running" | "exited";
101
+ exitCode: number | null;
102
+ startTime: number;
103
+ exitTime: number | null;
104
+ }
105
+ export interface ManagedProcess {
106
+ pid: number;
107
+ writeStdin(data: Uint8Array | string): void;
108
+ closeStdin(): void;
109
+ kill(signal?: number): void;
110
+ wait(): Promise<number>;
111
+ readonly exitCode: number | null;
112
+ }
113
+ export interface ShellHandle {
114
+ pid: number;
115
+ write(data: Uint8Array | string): void;
116
+ onData: ((data: Uint8Array) => void) | null;
117
+ resize(cols: number, rows: number): void;
118
+ kill(signal?: number): void;
119
+ wait(): Promise<number>;
120
+ }
121
+ export interface OpenShellOptions {
122
+ command?: string;
123
+ args?: string[];
124
+ env?: Record<string, string>;
125
+ cwd?: string;
126
+ cols?: number;
127
+ rows?: number;
128
+ onStderr?: (data: Uint8Array) => void;
129
+ }
130
+ export interface ConnectTerminalOptions extends OpenShellOptions {
131
+ onData?: (data: Uint8Array) => void;
132
+ }
133
+ export interface ExecOptions {
134
+ env?: Record<string, string>;
135
+ cwd?: string;
136
+ stdin?: string | Uint8Array;
137
+ timeout?: number;
138
+ onStdout?: (data: Uint8Array) => void;
139
+ onStderr?: (data: Uint8Array) => void;
140
+ captureStdio?: boolean;
141
+ filePath?: string;
142
+ cpuTimeLimitMs?: number;
143
+ timingMitigation?: TimingMitigation;
144
+ }
145
+ export interface ExecResult {
146
+ exitCode: number;
147
+ stdout: string;
148
+ stderr: string;
149
+ }
150
+ export interface RunResult<T = unknown> {
151
+ value?: T;
152
+ code: number;
153
+ errorMessage?: string;
154
+ }
155
+ export interface KernelSpawnOptions extends ExecOptions {
156
+ stdio?: "pipe" | "inherit";
157
+ stdinFd?: number;
158
+ stdoutFd?: number;
159
+ stderrFd?: number;
160
+ streamStdin?: boolean;
161
+ }
162
+ export type KernelExecOptions = ExecOptions;
163
+ export type KernelExecResult = ExecResult;
164
+ export type StatInfo = VirtualStat;
165
+ export type DirEntry = VirtualDirEntry;
166
+ export type StdioEvent = {
167
+ channel: StdioChannel;
168
+ message: string;
169
+ };
170
+ export type StdioHook = (event: StdioEvent) => void;
171
+ export interface Permissions {
172
+ fs?: FsPermissions;
173
+ network?: NetworkPermissions;
174
+ childProcess?: ChildProcessPermissions;
175
+ process?: ProcessPermissions;
176
+ env?: EnvPermissions;
177
+ tool?: ToolPermissions;
178
+ }
179
+ /** A worked example shown alongside a registered host tool. */
180
+ export interface HostToolExample {
181
+ /** What this example demonstrates. */
182
+ description: string;
183
+ /** Example input matching the tool's input schema. */
184
+ input: unknown;
185
+ }
186
+ /**
187
+ * A host-side tool that guest code can invoke as a shell command. The guest
188
+ * runs the tool by name and the invocation round-trips back to the host JS
189
+ * `handler`, whose return value is passed back to the guest. Tools never run
190
+ * inside the guest: they execute on the host, so they are the bridge for giving
191
+ * sandboxed guest code controlled, named capabilities (the kind AI agents call
192
+ * as tools).
193
+ */
194
+ export interface HostToolDefinition {
195
+ /** Human-readable description of what the tool does. */
196
+ description: string;
197
+ /** JSON Schema describing the tool's input. */
198
+ inputSchema: object;
199
+ /** Abort the invocation after this many milliseconds. */
200
+ timeoutMs?: number;
201
+ /** Worked examples shown alongside the tool. */
202
+ examples?: HostToolExample[];
203
+ /**
204
+ * Extra command names the guest can use to invoke this tool, in addition to
205
+ * the key it is registered under.
206
+ */
207
+ commandAliases?: string[];
208
+ /**
209
+ * Host handler invoked when guest code runs the tool. Receives the parsed
210
+ * input and returns a JSON-serializable result delivered back to the guest.
211
+ */
212
+ handler: (input: unknown) => unknown | Promise<unknown>;
213
+ }
214
+ export interface ResourceBudgets {
215
+ maxOutputBytes?: number;
216
+ maxBridgeCalls?: number;
217
+ maxTimers?: number;
218
+ maxChildProcesses?: number;
219
+ maxHandles?: number;
220
+ }
221
+ export interface ProcessConfig {
222
+ cwd?: string;
223
+ env?: Record<string, string>;
224
+ argv?: string[];
225
+ stdinIsTTY?: boolean;
226
+ stdoutIsTTY?: boolean;
227
+ stderrIsTTY?: boolean;
228
+ }
229
+ export interface OSConfig {
230
+ homedir?: string;
231
+ tmpdir?: string;
232
+ }
233
+ export interface CommandExecutor {
234
+ spawn(command: string, args: string[], options?: KernelSpawnOptions): ManagedProcess;
235
+ }
236
+ export interface NetworkAdapter {
237
+ fetch(url: string, options?: {
238
+ method?: string;
239
+ headers?: Record<string, string>;
240
+ body?: unknown;
241
+ }): Promise<{
242
+ ok: boolean;
243
+ status: number;
244
+ statusText: string;
245
+ headers: Record<string, string>;
246
+ body: string;
247
+ url: string;
248
+ redirected: boolean;
249
+ }>;
250
+ dnsLookup(hostname: string): Promise<{
251
+ address?: string;
252
+ family?: number;
253
+ error?: string;
254
+ code?: string;
255
+ }>;
256
+ httpRequest(url: string, options?: {
257
+ method?: string;
258
+ headers?: Record<string, string>;
259
+ body?: unknown;
260
+ }): Promise<{
261
+ status: number;
262
+ statusText: string;
263
+ headers: Record<string, string>;
264
+ body: string;
265
+ url: string;
266
+ }>;
267
+ }
268
+ export interface SystemDriver {
269
+ filesystem?: VirtualFileSystem;
270
+ network?: NetworkAdapter;
271
+ commandExecutor?: CommandExecutor;
272
+ permissions?: Permissions;
273
+ runtime: {
274
+ process: ProcessConfig;
275
+ os: OSConfig;
276
+ };
277
+ }
278
+ export interface RuntimeDriverOptions {
279
+ system: SystemDriver;
280
+ runtime: {
281
+ process: ProcessConfig;
282
+ os: OSConfig;
283
+ };
284
+ memoryLimit?: number;
285
+ cpuTimeLimitMs?: number;
286
+ timingMitigation?: TimingMitigation;
287
+ onStdio?: StdioHook;
288
+ payloadLimits?: {
289
+ base64TransferBytes?: number;
290
+ jsonPayloadBytes?: number;
291
+ };
292
+ resourceBudgets?: ResourceBudgets;
293
+ }
294
+ export interface NodeRuntimeDriver {
295
+ exec(code: string, options?: ExecOptions): Promise<ExecResult>;
296
+ run<T = unknown>(code: string, filePath?: string): Promise<RunResult<T>>;
297
+ dispose(): void;
298
+ terminate?(): Promise<void>;
299
+ readonly network?: Pick<NetworkAdapter, "fetch" | "dnsLookup" | "httpRequest">;
300
+ }
301
+ export interface NodeRuntimeDriverFactory {
302
+ createRuntimeDriver(options: RuntimeDriverOptions): NodeRuntimeDriver;
303
+ }
304
+ export interface KernelInterface {
305
+ vfs: VirtualFileSystem;
306
+ }
307
+ export interface Kernel extends KernelInterface {
308
+ mount(driver: KernelRuntimeDriver): Promise<void>;
309
+ dispose(): Promise<void>;
310
+ exec(command: string, options?: KernelExecOptions): Promise<KernelExecResult>;
311
+ spawn(command: string, args: string[], options?: KernelSpawnOptions): ManagedProcess;
312
+ openShell(options?: OpenShellOptions): ShellHandle;
313
+ connectTerminal(options?: ConnectTerminalOptions): Promise<number>;
314
+ mountFs(path: string, fs: VirtualFileSystem, options?: {
315
+ readOnly?: boolean;
316
+ }): void;
317
+ unmountFs(path: string): void;
318
+ readFile(path: string): Promise<Uint8Array>;
319
+ writeFile(path: string, content: string | Uint8Array): Promise<void>;
320
+ mkdir(path: string): Promise<void>;
321
+ readdir(path: string): Promise<string[]>;
322
+ stat(path: string): Promise<VirtualStat>;
323
+ exists(path: string): Promise<boolean>;
324
+ removeFile(path: string): Promise<void>;
325
+ removeDir(path: string): Promise<void>;
326
+ rename(oldPath: string, newPath: string): Promise<void>;
327
+ vmFetch(request: {
328
+ port: number;
329
+ method: string;
330
+ path: string;
331
+ headersJson: string;
332
+ body?: string;
333
+ }): Promise<string>;
334
+ registerHostTools(tools: Record<string, HostToolDefinition>): Promise<void>;
335
+ readonly commands: ReadonlyMap<string, string>;
336
+ readonly processes: ReadonlyMap<number, ProcessInfo>;
337
+ readonly env: Record<string, string>;
338
+ readonly cwd: string;
339
+ readonly socketTable: {
340
+ hasHostNetworkAdapter(): boolean;
341
+ findListener(_request: unknown): unknown | null;
342
+ findBoundUdp(_request: unknown): unknown | null;
343
+ };
344
+ readonly processTable: {
345
+ getSignalState(_pid: number): {
346
+ handlers: Map<number, unknown>;
347
+ };
348
+ };
349
+ readonly timerTable: Record<string, never>;
350
+ readonly zombieTimerCount: number;
351
+ }
352
+ export interface BindingTree {
353
+ [key: string]: BindingFunction | BindingTree;
354
+ }
355
+ export type BindingFunction = (...args: unknown[]) => unknown;
356
+ export interface ModuleAccessOptions {
357
+ cwd?: string;
358
+ }
359
+ export interface NodeDriverOptions {
360
+ filesystem?: VirtualFileSystem;
361
+ networkAdapter?: NetworkAdapter;
362
+ commandExecutor?: CommandExecutor;
363
+ permissions?: Permissions;
364
+ processConfig?: ProcessConfig;
365
+ osConfig?: OSConfig;
366
+ moduleAccess?: ModuleAccessOptions;
367
+ }
368
+ export interface DefaultNetworkAdapterOptions {
369
+ loopbackExemptPorts?: number[];
370
+ }
371
+ export interface NodeRuntimeOptions {
372
+ systemDriver?: SystemDriver;
373
+ runtimeDriverFactory?: NodeRuntimeDriverFactory;
374
+ permissions?: Partial<Permissions>;
375
+ memoryLimit?: number;
376
+ moduleAccessPaths?: string[];
377
+ bindings?: BindingTree;
378
+ loopbackExemptPorts?: number[];
379
+ moduleAccessCwd?: string;
380
+ packageRoots?: Array<{
381
+ hostPath: string;
382
+ vmPath: string;
383
+ }>;
384
+ }
385
+ export type NodeRuntimeDriverFactoryOptions = Record<string, never>;
386
+ export type NodeExecutionDriverOptions = RuntimeDriverOptions;
387
+ export interface KernelRuntimeDriver {
388
+ readonly kind: "node" | "wasmvm";
389
+ readonly name: string;
390
+ readonly commands: string[];
391
+ readonly commandDirs?: string[];
392
+ init?(kernel: KernelInterface): Promise<void> | void;
393
+ tryResolve?(command: string): boolean;
394
+ getGuestCommandPaths?(startIndex: number): ReadonlyMap<string, string>;
395
+ recordModuleExecution?(command: string): void;
396
+ }
397
+ export type DriverProcess = ManagedProcess;
398
+ export type ProcessContext = Record<string, never>;
399
+ export declare class KernelError extends Error {
400
+ readonly code: string;
401
+ constructor(code: string, message: string);
402
+ }
403
+ export declare class InMemoryFileSystem implements VirtualFileSystem {
404
+ private readonly entries;
405
+ constructor();
406
+ readFile(targetPath: string): Promise<Uint8Array>;
407
+ readTextFile(targetPath: string): Promise<string>;
408
+ readDir(targetPath: string): Promise<string[]>;
409
+ readDirWithTypes(targetPath: string): Promise<VirtualDirEntry[]>;
410
+ writeFile(targetPath: string, content: string | Uint8Array): Promise<void>;
411
+ createDir(targetPath: string): Promise<void>;
412
+ mkdir(targetPath: string, options?: {
413
+ recursive?: boolean;
414
+ }): Promise<void>;
415
+ exists(targetPath: string): Promise<boolean>;
416
+ stat(targetPath: string): Promise<VirtualStat>;
417
+ removeFile(targetPath: string): Promise<void>;
418
+ removeDir(targetPath: string): Promise<void>;
419
+ rename(oldPath: string, newPath: string): Promise<void>;
420
+ realpath(targetPath: string): Promise<string>;
421
+ symlink(target: string, linkPath: string): Promise<void>;
422
+ readlink(targetPath: string): Promise<string>;
423
+ lstat(targetPath: string): Promise<VirtualStat>;
424
+ link(oldPath: string, newPath: string): Promise<void>;
425
+ chmod(targetPath: string, mode: number): Promise<void>;
426
+ chown(targetPath: string, uid: number, gid: number): Promise<void>;
427
+ utimes(targetPath: string, atime: number, mtime: number): Promise<void>;
428
+ truncate(targetPath: string, length: number): Promise<void>;
429
+ pread(targetPath: string, offset: number, length: number): Promise<Uint8Array>;
430
+ pwrite(targetPath: string, offset: number, data: Uint8Array): Promise<void>;
431
+ private resolvePath;
432
+ private resolveEntry;
433
+ private newDirectory;
434
+ private toStat;
435
+ }
436
+ export declare function createInMemoryFileSystem(): InMemoryFileSystem;
437
+ export declare class NodeFileSystem implements VirtualFileSystem {
438
+ readonly rootPath: string;
439
+ constructor(options: {
440
+ root: string;
441
+ });
442
+ private normalizeTarget;
443
+ private toStat;
444
+ readFile(targetPath: string): Promise<Uint8Array>;
445
+ readTextFile(targetPath: string): Promise<string>;
446
+ readDir(targetPath: string): Promise<string[]>;
447
+ readDirWithTypes(targetPath: string): Promise<VirtualDirEntry[]>;
448
+ writeFile(targetPath: string, content: string | Uint8Array): Promise<void>;
449
+ createDir(targetPath: string): Promise<void>;
450
+ mkdir(targetPath: string, options?: {
451
+ recursive?: boolean;
452
+ }): Promise<void>;
453
+ exists(targetPath: string): Promise<boolean>;
454
+ stat(targetPath: string): Promise<VirtualStat>;
455
+ removeFile(targetPath: string): Promise<void>;
456
+ removeDir(targetPath: string): Promise<void>;
457
+ rename(oldPath: string, newPath: string): Promise<void>;
458
+ realpath(targetPath: string): Promise<string>;
459
+ symlink(target: string, linkPath: string): Promise<void>;
460
+ readlink(targetPath: string): Promise<string>;
461
+ lstat(targetPath: string): Promise<VirtualStat>;
462
+ link(oldPath: string, newPath: string): Promise<void>;
463
+ chmod(targetPath: string, mode: number): Promise<void>;
464
+ chown(targetPath: string, uid: number, gid: number): Promise<void>;
465
+ utimes(targetPath: string, atime: number, mtime: number): Promise<void>;
466
+ truncate(targetPath: string, length: number): Promise<void>;
467
+ pread(targetPath: string, offset: number, length: number): Promise<Uint8Array>;
468
+ pwrite(targetPath: string, offset: number, data: Uint8Array): Promise<void>;
469
+ }
470
+ export declare const allowAllFs: FsPermissions;
471
+ export declare const allowAllNetwork: NetworkPermissions;
472
+ export declare const allowAllChildProcess: ChildProcessPermissions;
473
+ export declare const allowAllProcess: ProcessPermissions;
474
+ export declare const allowAllEnv: EnvPermissions;
475
+ export declare const allowAll: Permissions;
476
+ export declare function filterEnv(env: Record<string, string> | undefined, permissions?: Permissions): Record<string, string>;
477
+ export declare function createProcessScopedFileSystem(filesystem: VirtualFileSystem): VirtualFileSystem;
478
+ export declare function exists(filesystem: VirtualFileSystem, targetPath: string): Promise<boolean>;
479
+ export declare function stat(filesystem: VirtualFileSystem, targetPath: string): Promise<VirtualStat>;
480
+ export declare function rename(filesystem: VirtualFileSystem, oldPath: string, newPath: string): Promise<void>;
481
+ export declare function readDirWithTypes(filesystem: VirtualFileSystem, targetPath: string): Promise<VirtualDirEntry[]>;
482
+ export declare function mkdir(filesystem: VirtualFileSystem, targetPath: string, options?: {
483
+ recursive?: boolean;
484
+ }): Promise<void>;
485
+ export declare function createNodeHostCommandExecutor(): CommandExecutor;
486
+ export declare function createKernelCommandExecutor(kernel: Kernel): CommandExecutor;
487
+ export declare function createKernelVfsAdapter(kernelVfs: VirtualFileSystem): VirtualFileSystem;
488
+ export declare function createHostFallbackVfs(base: VirtualFileSystem): VirtualFileSystem;
489
+ export declare function isPrivateIp(host: string): boolean;
490
+ export declare function createNodeHostNetworkAdapter(): NetworkAdapter;
491
+ export declare function createDefaultNetworkAdapter(): NetworkAdapter;
492
+ export declare function createNodeDriver(options?: NodeDriverOptions): SystemDriver;
493
+ export declare class NodeExecutionDriver implements NodeRuntimeDriver {
494
+ private readonly options;
495
+ readonly network?: Pick<NetworkAdapter, "fetch" | "dnsLookup" | "httpRequest">;
496
+ constructor(options: RuntimeDriverOptions);
497
+ exec(): Promise<ExecResult>;
498
+ run<T = unknown>(): Promise<RunResult<T>>;
499
+ dispose(): void;
500
+ terminate(): Promise<void>;
501
+ }
502
+ export declare class NodeRuntime extends NodeExecutionDriver {
503
+ }
504
+ export declare function createNodeRuntimeDriverFactory(): NodeRuntimeDriverFactory;
505
+ export declare class ModuleAccessFileSystem extends NodeFileSystem {
506
+ }
507
+ export declare const WASMVM_COMMANDS: readonly string[];
508
+ export type PermissionTier = "full" | "read-write" | "read-only" | "isolated";
509
+ export declare const DEFAULT_FIRST_PARTY_TIERS: Readonly<Record<string, PermissionTier>>;
510
+ export interface WasmVmRuntimeOptions {
511
+ wasmBinaryPath?: string;
512
+ commandDirs?: string[];
513
+ permissions?: Record<string, PermissionTier>;
514
+ }
515
+ export declare function createWasmVmRuntime(options?: WasmVmRuntimeOptions): KernelRuntimeDriver;
516
+ export declare function createNodeRuntime(): KernelRuntimeDriver;
517
+ export declare function createKernel(options: {
518
+ filesystem: VirtualFileSystem;
519
+ permissions?: Permissions;
520
+ env?: Record<string, string>;
521
+ cwd?: string;
522
+ sidecar?: Sidecar;
523
+ onBootTiming?: (timing: KernelBootTiming) => void;
524
+ maxProcesses?: number;
525
+ hostNetworkAdapter?: unknown;
526
+ loopbackExemptPorts?: number[];
527
+ logger?: unknown;
528
+ mounts?: Array<{
529
+ path: string;
530
+ fs: VirtualFileSystem;
531
+ readOnly?: boolean;
532
+ }>;
533
+ syncFilesystemOnDispose?: boolean;
534
+ }): Kernel;