@cloudflare/sandbox 0.7.20 → 0.8.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.
@@ -51,42 +51,25 @@ function partitionEnvVars(envVars) {
51
51
  }
52
52
 
53
53
  //#endregion
54
- //#region ../shared/dist/git.js
54
+ //#region ../shared/dist/logger/sanitize.js
55
55
  /**
56
- * Fallback repository name used when URL parsing fails
56
+ * Log-only sanitization helpers
57
+ *
58
+ * These functions redact sensitive values for logging output.
59
+ * They MUST NOT be used to mutate command strings before execution.
57
60
  */
58
- const FALLBACK_REPO_NAME = "repository";
59
61
  /**
60
- * Extract repository name from a Git URL
61
- *
62
- * Supports multiple URL formats:
63
- * - HTTPS: https://github.com/user/repo.git → repo
64
- * - HTTPS without .git: https://github.com/user/repo → repo
65
- * - SSH: git@github.com:user/repo.git → repo
66
- * - GitLab/others: https://gitlab.com/org/project.git → project
67
- *
68
- * @param repoUrl - Git repository URL (HTTPS or SSH format)
69
- * @returns Repository name extracted from URL, or 'repository' as fallback
62
+ * Sensitive query parameter names to redact from URLs.
63
+ * Anchored to query string context ([?&]) to avoid matching path segments.
64
+ * Value matching stops at & and common URL/command delimiters.
70
65
  */
71
- function extractRepoName(repoUrl) {
72
- try {
73
- const pathParts = new URL(repoUrl).pathname.split("/");
74
- const lastPart = pathParts[pathParts.length - 1];
75
- if (lastPart) return lastPart.replace(/\.git$/, "");
76
- } catch {}
77
- if (repoUrl.includes(":") || repoUrl.includes("/")) {
78
- const segments = repoUrl.split(/[:/]/).filter(Boolean);
79
- const lastSegment = segments[segments.length - 1];
80
- if (lastSegment) return lastSegment.replace(/\.git$/, "");
81
- }
82
- return FALLBACK_REPO_NAME;
83
- }
66
+ const SENSITIVE_PARAMS = /([?&])(X-Amz-Credential|X-Amz-Signature|X-Amz-Security-Token|token|secret|password)=[^&\s"'`<>]*/gi;
84
67
  /**
85
68
  * Redact credentials from URLs for secure logging
86
69
  *
87
70
  * Replaces any credentials (username:password, tokens, etc.) embedded
88
71
  * in URLs with ****** to prevent sensitive data exposure in logs.
89
- * Works with URLs embedded in text (e.g., "Error: https://token@github.com/repo.git failed")
72
+ * Works with URLs embedded in text.
90
73
  *
91
74
  * @param text - String that may contain URLs with credentials
92
75
  * @returns String with credentials redacted from any URLs
@@ -123,11 +106,88 @@ function redactCredentials(text) {
123
106
  return result;
124
107
  }
125
108
  /**
109
+ * Redact sensitive query parameters from URLs
110
+ *
111
+ * Strips X-Amz-Credential, X-Amz-Signature, X-Amz-Security-Token,
112
+ * token, secret, and password query params from URLs. Returns
113
+ * non-URL strings unchanged.
114
+ *
115
+ * @param input - String that may contain URLs with sensitive params
116
+ * @returns String with sensitive params replaced by REDACTED
117
+ */
118
+ function redactSensitiveParams(input) {
119
+ if (!input.includes("?") || !input.includes("=")) return input;
120
+ return input.replace(SENSITIVE_PARAMS, "$1$2=REDACTED");
121
+ }
122
+ /**
123
+ * Redact sensitive data from a command string for logging
124
+ *
125
+ * Composes redactCredentials (URL credentials) and redactSensitiveParams
126
+ * (presigned URL query params). For log values only — never mutate
127
+ * command strings before execution.
128
+ *
129
+ * @param command - Command string to sanitize for logging
130
+ * @returns Sanitized command string
131
+ */
132
+ function redactCommand(command) {
133
+ return redactSensitiveParams(redactCredentials(command));
134
+ }
135
+ /**
136
+ * Truncate a string for log output with a truncation indicator
137
+ *
138
+ * @param value - String to potentially truncate
139
+ * @param maxLen - Maximum length before truncation (default 120)
140
+ * @returns Object with truncated value and boolean flag
141
+ */
142
+ function truncateForLog(value, maxLen = 120) {
143
+ if (value.length <= maxLen) return {
144
+ value,
145
+ truncated: false
146
+ };
147
+ const cutoff = Math.max(0, maxLen - 3);
148
+ return {
149
+ value: `${value.substring(0, cutoff)}...`,
150
+ truncated: true
151
+ };
152
+ }
153
+
154
+ //#endregion
155
+ //#region ../shared/dist/git.js
156
+ /**
157
+ * Fallback repository name used when URL parsing fails
158
+ */
159
+ const FALLBACK_REPO_NAME = "repository";
160
+ /**
161
+ * Extract repository name from a Git URL
162
+ *
163
+ * Supports multiple URL formats:
164
+ * - HTTPS: https://github.com/user/repo.git → repo
165
+ * - HTTPS without .git: https://github.com/user/repo → repo
166
+ * - SSH: git@github.com:user/repo.git → repo
167
+ * - GitLab/others: https://gitlab.com/org/project.git → project
168
+ *
169
+ * @param repoUrl - Git repository URL (HTTPS or SSH format)
170
+ * @returns Repository name extracted from URL, or 'repository' as fallback
171
+ */
172
+ function extractRepoName(repoUrl) {
173
+ try {
174
+ const pathParts = new URL(repoUrl).pathname.split("/");
175
+ const lastPart = pathParts[pathParts.length - 1];
176
+ if (lastPart) return lastPart.replace(/\.git$/, "");
177
+ } catch {}
178
+ if (repoUrl.includes(":") || repoUrl.includes("/")) {
179
+ const segments = repoUrl.split(/[:/]/).filter(Boolean);
180
+ const lastSegment = segments[segments.length - 1];
181
+ if (lastSegment) return lastSegment.replace(/\.git$/, "");
182
+ }
183
+ return FALLBACK_REPO_NAME;
184
+ }
185
+ /**
126
186
  * Sanitize data by redacting credentials from any strings
127
187
  * Recursively processes objects and arrays to ensure credentials are never leaked
128
188
  */
129
189
  function sanitizeGitData(data) {
130
- if (typeof data === "string") return redactCredentials(data);
190
+ if (typeof data === "string") return redactCommand(data);
131
191
  if (data === null || data === void 0) return data;
132
192
  if (Array.isArray(data)) return data.map((item) => sanitizeGitData(item));
133
193
  if (typeof data === "object") {
@@ -150,9 +210,9 @@ var GitLogger = class GitLogger {
150
210
  }
151
211
  sanitizeError(error) {
152
212
  if (!error) return error;
153
- const sanitized = new Error(redactCredentials(error.message));
213
+ const sanitized = new Error(redactCommand(error.message));
154
214
  sanitized.name = error.name;
155
- if (error.stack) sanitized.stack = redactCredentials(error.stack);
215
+ if (error.stack) sanitized.stack = redactCommand(error.stack);
156
216
  const sanitizedRecord = sanitized;
157
217
  const errorRecord = error;
158
218
  for (const key of Object.keys(error)) if (key !== "message" && key !== "stack" && key !== "name") sanitizedRecord[key] = sanitizeGitData(errorRecord[key]);
@@ -283,6 +343,128 @@ var ResultImpl = class {
283
343
  }
284
344
  };
285
345
 
346
+ //#endregion
347
+ //#region ../shared/dist/logger/canonical.js
348
+ /** Events that are low-value at info on success */
349
+ const DEBUG_ON_SUCCESS = new Set([
350
+ "session.create",
351
+ "session.destroy",
352
+ "file.read",
353
+ "file.write",
354
+ "file.delete",
355
+ "file.mkdir"
356
+ ]);
357
+ function resolveLogLevel(payload, options) {
358
+ if (payload.outcome === "error") return "error";
359
+ if (options?.successLevel) return options.successLevel;
360
+ if (payload.origin === "internal") return "debug";
361
+ if (DEBUG_ON_SUCCESS.has(payload.event)) return "debug";
362
+ return "info";
363
+ }
364
+ /**
365
+ * Sanitize an Error object by redacting sensitive data from message and stack.
366
+ * Produces a copy so the caller's original Error is not mutated.
367
+ */
368
+ function sanitizeError(error) {
369
+ if (!error) return void 0;
370
+ const sanitized = new Error(redactCommand(error.message));
371
+ sanitized.name = error.name;
372
+ sanitized.stack = error.stack ? redactCommand(error.stack) : void 0;
373
+ return sanitized;
374
+ }
375
+ /**
376
+ * Sanitize and prepare payload fields for both message building and context emission.
377
+ * Called once by logCanonicalEvent to avoid double-redaction.
378
+ */
379
+ function sanitizePayload(payload) {
380
+ if (payload.command === void 0) return { commandTruncated: false };
381
+ const { value, truncated } = truncateForLog(redactCommand(payload.command));
382
+ return {
383
+ sanitizedCommand: value,
384
+ commandTruncated: truncated
385
+ };
386
+ }
387
+ /**
388
+ * Build a human-readable canonical event message for dashboards and log viewers.
389
+ *
390
+ * Format: `{event} {outcome} {key_context} [— {reason}] ({durationMs}ms[, {sizeBytes}B])`
391
+ *
392
+ * The if/else chain for key context has implicit priority: command > path >
393
+ * sessionId > port > repoUrl > pid. If a payload has multiple, only the
394
+ * highest-priority one appears in the message. All fields are still present
395
+ * as discrete queryable keys in the structured log context.
396
+ */
397
+ function buildMessage(payload, sanitizedCommand) {
398
+ const { event } = payload;
399
+ if (event === "version.check") {
400
+ const parts$1 = ["version.check"];
401
+ if (payload.sdkVersion) parts$1.push(`sdk=${payload.sdkVersion}`);
402
+ if (payload.containerVersion) parts$1.push(`container=${payload.containerVersion}`);
403
+ if (payload.versionOutcome && payload.versionOutcome !== "compatible") parts$1.push(`(${payload.versionOutcome})`);
404
+ return parts$1.join(" ");
405
+ }
406
+ const parts = [event, payload.outcome];
407
+ if (sanitizedCommand !== void 0) parts.push(sanitizedCommand);
408
+ else if (payload.command !== void 0) {
409
+ const { value } = truncateForLog(redactCommand(payload.command));
410
+ parts.push(value);
411
+ } else if (payload.path !== void 0) parts.push(payload.path);
412
+ else if (event.includes("session") && payload.sessionId !== void 0) parts.push(payload.sessionId);
413
+ else if (payload.port !== void 0) parts.push(String(payload.port));
414
+ else if (payload.repoUrl !== void 0) {
415
+ let gitContext = payload.repoUrl;
416
+ if (payload.branch !== void 0) gitContext += ` ${payload.branch}`;
417
+ parts.push(gitContext);
418
+ } else if (payload.pid !== void 0) parts.push(String(payload.pid));
419
+ else if (payload.backupId !== void 0) parts.push(payload.backupId);
420
+ else if (payload.repoPath !== void 0) {
421
+ let gitContext = payload.repoPath;
422
+ if (payload.branch !== void 0) gitContext += ` branch=${payload.branch}`;
423
+ parts.push(gitContext);
424
+ } else if (payload.mountsProcessed !== void 0) {
425
+ let destroyContext = `${payload.mountsProcessed} mounts`;
426
+ if (payload.mountFailures) destroyContext += `, ${payload.mountFailures} failed`;
427
+ parts.push(destroyContext);
428
+ } else if (payload.mountPath !== void 0) parts.push(payload.mountPath);
429
+ if (payload.outcome === "error") {
430
+ if (payload.errorMessage !== void 0) parts.push(`\u2014 ${payload.errorMessage}`);
431
+ else if (payload.exitCode !== void 0) parts.push(`\u2014 exitCode=${payload.exitCode}`);
432
+ }
433
+ const durationSuffix = payload.sizeBytes !== void 0 ? `(${payload.durationMs}ms, ${payload.sizeBytes}B)` : `(${payload.durationMs}ms)`;
434
+ parts.push(durationSuffix);
435
+ return parts.join(" ");
436
+ }
437
+ /**
438
+ * Log a canonical event — the single entry point for all structured operational events.
439
+ *
440
+ * Sanitizes command fields once, builds the message, selects log level from
441
+ * outcome, and emits a structured log entry with the full payload as context.
442
+ */
443
+ function logCanonicalEvent(logger, payload, options) {
444
+ const resolvedErrorMessage = payload.errorMessage ?? payload.error?.message;
445
+ const sanitizedErrorMessage = resolvedErrorMessage ? redactCommand(resolvedErrorMessage) : void 0;
446
+ const enrichedPayload = sanitizedErrorMessage !== void 0 ? {
447
+ ...payload,
448
+ errorMessage: sanitizedErrorMessage
449
+ } : payload;
450
+ const { sanitizedCommand, commandTruncated } = sanitizePayload(enrichedPayload);
451
+ const message = buildMessage(enrichedPayload, sanitizedCommand);
452
+ const context = {};
453
+ for (const [key, value] of Object.entries(enrichedPayload)) {
454
+ if (key === "error") continue;
455
+ context[key] = value;
456
+ }
457
+ if (sanitizedCommand !== void 0) {
458
+ context.command = sanitizedCommand;
459
+ if (commandTruncated) context.commandTruncated = true;
460
+ }
461
+ const level = resolveLogLevel(enrichedPayload, options);
462
+ if (level === "error") logger.error(message, sanitizeError(payload.error), context);
463
+ else if (level === "warn") logger.warn(message, context);
464
+ else if (level === "debug") logger.debug(message, context);
465
+ else logger.info(message, context);
466
+ }
467
+
286
468
  //#endregion
287
469
  //#region ../shared/dist/logger/types.js
288
470
  /**
@@ -324,18 +506,18 @@ const COLORS = {
324
506
  var CloudflareLogger = class CloudflareLogger {
325
507
  baseContext;
326
508
  minLevel;
327
- pretty;
509
+ outputMode;
328
510
  /**
329
511
  * Create a new CloudflareLogger
330
512
  *
331
513
  * @param baseContext Base context included in all log entries
332
514
  * @param minLevel Minimum log level to output (default: INFO)
333
- * @param pretty Enable pretty printing for human-readable output (default: false)
515
+ * @param outputMode How log entries are formatted and emitted (default: 'structured')
334
516
  */
335
- constructor(baseContext, minLevel = LogLevel.INFO, pretty = false) {
517
+ constructor(baseContext, minLevel = LogLevel.INFO, outputMode = "structured") {
336
518
  this.baseContext = baseContext;
337
519
  this.minLevel = minLevel;
338
- this.pretty = pretty;
520
+ this.outputMode = outputMode;
339
521
  }
340
522
  /**
341
523
  * Log debug-level message
@@ -380,7 +562,7 @@ var CloudflareLogger = class CloudflareLogger {
380
562
  return new CloudflareLogger({
381
563
  ...this.baseContext,
382
564
  ...context
383
- }, this.minLevel, this.pretty);
565
+ }, this.minLevel, this.outputMode);
384
566
  }
385
567
  /**
386
568
  * Check if a log level should be output
@@ -394,7 +576,7 @@ var CloudflareLogger = class CloudflareLogger {
394
576
  buildLogData(level, message, context, error) {
395
577
  const logData = {
396
578
  level,
397
- msg: message,
579
+ message,
398
580
  ...this.baseContext,
399
581
  ...context,
400
582
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
@@ -407,47 +589,75 @@ var CloudflareLogger = class CloudflareLogger {
407
589
  return logData;
408
590
  }
409
591
  /**
410
- * Output log data to console (pretty or JSON)
592
+ * Output log data using the configured output mode
411
593
  */
412
594
  output(consoleFn, data) {
413
- if (this.pretty) this.outputPretty(consoleFn, data);
414
- else this.outputJson(consoleFn, data);
595
+ switch (this.outputMode) {
596
+ case "pretty":
597
+ this.outputPretty(consoleFn, data);
598
+ break;
599
+ case "json-line":
600
+ this.outputJsonLine(consoleFn, data);
601
+ break;
602
+ case "structured":
603
+ this.outputStructured(consoleFn, data);
604
+ break;
605
+ }
415
606
  }
416
607
  /**
417
- * Output as JSON (production)
608
+ * Output as JSON string (container stdout — parsed by Containers pipeline)
418
609
  */
419
- outputJson(consoleFn, data) {
610
+ outputJsonLine(consoleFn, data) {
420
611
  consoleFn(JSON.stringify(data));
421
612
  }
422
613
  /**
614
+ * Output as raw object (Workers/DOs — Workers Logs auto-indexes fields)
615
+ */
616
+ outputStructured(consoleFn, data) {
617
+ consoleFn(data);
618
+ }
619
+ /**
423
620
  * Output as pretty-printed, colored text (development)
424
621
  *
425
- * Format: LEVEL [component] message (trace: tr_...) {context}
426
- * Example: INFO [sandbox-do] Command started (trace: tr_7f3a9b2c) {commandId: "cmd-123"}
622
+ * Each log event is a single consoleFn() call so it appears as one entry
623
+ * in the Cloudflare dashboard. Context is rendered inline as compact key=value pairs.
624
+ *
625
+ * Format: LEVEL [component] message trace=tr_... key=value key=value
427
626
  */
428
627
  outputPretty(consoleFn, data) {
429
- const { level, msg, timestamp, traceId, component, sandboxId, sessionId, processId, commandId, operation, duration, error, ...rest } = data;
628
+ const { level, message: msg, timestamp, traceId, component, sandboxId, sessionId, processId, commandId, durationMs, serviceVersion, instanceId, error, ...rest } = data;
430
629
  const levelStr = String(level || "INFO").toUpperCase();
431
630
  const levelColor = this.getLevelColor(levelStr);
432
631
  const componentBadge = component ? `[${component}]` : "";
433
- const traceIdShort = traceId ? String(traceId).substring(0, 12) : "";
434
- let logLine = `${levelColor}${levelStr.padEnd(5)}${COLORS.reset} ${componentBadge} ${msg}`;
435
- if (traceIdShort) logLine += ` ${COLORS.dim}(trace: ${traceIdShort})${COLORS.reset}`;
436
- const contextFields = [];
437
- if (operation) contextFields.push(`operation: ${operation}`);
438
- if (commandId) contextFields.push(`commandId: ${String(commandId).substring(0, 12)}`);
439
- if (sandboxId) contextFields.push(`sandboxId: ${sandboxId}`);
440
- if (sessionId) contextFields.push(`sessionId: ${String(sessionId).substring(0, 12)}`);
441
- if (processId) contextFields.push(`processId: ${processId}`);
442
- if (duration !== void 0) contextFields.push(`duration: ${duration}ms`);
443
- if (contextFields.length > 0) logLine += ` ${COLORS.dim}{${contextFields.join(", ")}}${COLORS.reset}`;
444
- consoleFn(logLine);
632
+ let logLine = `${timestamp ? `${COLORS.dim}${new Date(timestamp).toISOString().substring(11, 23)}${COLORS.reset} ` : ""}${levelColor}${levelStr.padEnd(5)}${COLORS.reset} ${componentBadge} ${msg}`;
633
+ const pairs = [];
634
+ if (traceId) pairs.push(`trace=${String(traceId).substring(0, 12)}`);
635
+ if (commandId) pairs.push(`cmd=${String(commandId).substring(0, 12)}`);
636
+ if (sandboxId) pairs.push(`sandbox=${sandboxId}`);
637
+ if (sessionId) pairs.push(`session=${String(sessionId).substring(0, 12)}`);
638
+ if (processId) pairs.push(`proc=${processId}`);
639
+ if (durationMs !== void 0) pairs.push(`dur=${durationMs}ms`);
640
+ for (const [key, value] of Object.entries(rest)) {
641
+ if (value === void 0 || value === null) continue;
642
+ const v = typeof value === "object" ? JSON.stringify(value) : this.sanitizePrettyValue(String(value));
643
+ pairs.push(`${key}=${v}`);
644
+ }
445
645
  if (error && typeof error === "object") {
446
646
  const errorObj = error;
447
- if (errorObj.message) consoleFn(` ${COLORS.error}Error: ${errorObj.message}${COLORS.reset}`);
448
- if (errorObj.stack) consoleFn(` ${COLORS.dim}${errorObj.stack}${COLORS.reset}`);
647
+ if (errorObj.name) pairs.push(`err.name=${this.sanitizePrettyValue(errorObj.name)}`);
648
+ if (errorObj.message) pairs.push(`err.msg=${this.sanitizePrettyValue(errorObj.message)}`);
649
+ if (errorObj.stack) pairs.push(`err.stack=${this.sanitizePrettyValue(errorObj.stack)}`);
449
650
  }
450
- if (Object.keys(rest).length > 0) consoleFn(` ${COLORS.dim}${JSON.stringify(rest, null, 2)}${COLORS.reset}`);
651
+ if (pairs.length > 0) logLine += ` ${COLORS.dim}${pairs.join(" ")}${COLORS.reset}`;
652
+ consoleFn(logLine);
653
+ }
654
+ /**
655
+ * Collapse newlines so a single consoleFn() call stays on one line.
656
+ * Cloudflare's log pipeline splits on literal newlines, which fragments
657
+ * stack traces and multi-line error messages into separate entries.
658
+ */
659
+ sanitizePrettyValue(value) {
660
+ return value.replace(/\r/g, "\\r").replace(/\n/g, "\\n");
451
661
  }
452
662
  /**
453
663
  * Get ANSI color code for log level
@@ -527,8 +737,7 @@ var TraceContext = class TraceContext {
527
737
  *
528
738
  * Provides structured, trace-aware logging with:
529
739
  * - Explicit logger passing via constructor injection
530
- * - Pretty printing for local development
531
- * - JSON output for production
740
+ * - Three output modes: structured (Workers/DOs), json-line (container), pretty (local dev)
532
741
  * - Environment auto-detection
533
742
  * - Log level configuration
534
743
  *
@@ -542,7 +751,7 @@ var TraceContext = class TraceContext {
542
751
  * const service = new MyService(logger);
543
752
  *
544
753
  * // Create child loggers for additional context
545
- * const execLogger = logger.child({ operation: 'exec', commandId: 'cmd-456' });
754
+ * const execLogger = logger.child({ commandId: 'cmd-456' });
546
755
  * execLogger.info('Operation started');
547
756
  * ```
548
757
  */
@@ -598,12 +807,14 @@ function createNoOpLogger() {
598
807
  */
599
808
  function createLogger(context) {
600
809
  const minLevel = getLogLevelFromEnv();
601
- const pretty = isPrettyPrintEnabled();
810
+ const outputMode = getOutputMode(context.component);
602
811
  return new CloudflareLogger({
603
812
  ...context,
604
813
  traceId: context.traceId || TraceContext.generate(),
605
- component: context.component
606
- }, minLevel, pretty);
814
+ component: context.component,
815
+ serviceVersion: context.serviceVersion || getEnvVar("SANDBOX_VERSION") || void 0,
816
+ instanceId: context.instanceId || getEnvVar("HOSTNAME") || getEnvVar("SANDBOX_INSTANCE_ID") || void 0
817
+ }, minLevel, outputMode);
607
818
  }
608
819
  /**
609
820
  * Get log level from environment variable
@@ -621,16 +832,20 @@ function getLogLevelFromEnv() {
621
832
  }
622
833
  }
623
834
  /**
624
- * Check if pretty printing should be enabled
835
+ * Determine output mode based on component and environment:
836
+ * - SANDBOX_LOG_FORMAT=pretty → 'pretty' for all components (local wrangler dev)
837
+ * - Container/Executor without pretty → 'json-line' (Bun stdout → Containers pipeline)
838
+ * - Everything else without pretty → 'structured' (Workers/DOs → Workers Logs)
625
839
  *
626
- * Checks SANDBOX_LOG_FORMAT env var, falls back to auto-detection:
627
- * - Local development: pretty (colored, human-readable)
628
- * - Production: json (structured)
840
+ * In local dev, setting SANDBOX_LOG_FORMAT=pretty gives readable terminal
841
+ * output on both the DO side and container side. In production (where the
842
+ * var isn't set), DOs emit structured objects and containers emit single-line
843
+ * JSON — both queryable by their respective observability pipelines.
629
844
  */
630
- function isPrettyPrintEnabled() {
631
- const format = getEnvVar("SANDBOX_LOG_FORMAT");
632
- if (format) return format.toLowerCase() === "pretty";
633
- return false;
845
+ function getOutputMode(component) {
846
+ if (getEnvVar("SANDBOX_LOG_FORMAT")?.toLowerCase() === "pretty") return "pretty";
847
+ if (component === "container" || component === "executor") return "json-line";
848
+ return "structured";
634
849
  }
635
850
  /**
636
851
  * Get environment variable value
@@ -756,5 +971,5 @@ function generateRequestId() {
756
971
  }
757
972
 
758
973
  //#endregion
759
- export { filterEnvVars as _, isExecResult as a, parseSSEFrames as c, createNoOpLogger as d, TraceContext as f, extractRepoName as g, GitLogger as h, isWSStreamChunk as i, shellEscape as l, ResultImpl as m, isWSError as n, isProcess as o, Execution as p, isWSResponse as r, isProcessStatus as s, generateRequestId as t, createLogger as u, getEnvString as v, partitionEnvVars as y };
760
- //# sourceMappingURL=dist-CwUZf_TJ.js.map
974
+ export { extractRepoName as _, isExecResult as a, partitionEnvVars as b, parseSSEFrames as c, createNoOpLogger as d, TraceContext as f, GitLogger as g, ResultImpl as h, isWSStreamChunk as i, shellEscape as l, Execution as m, isWSError as n, isProcess as o, logCanonicalEvent as p, isWSResponse as r, isProcessStatus as s, generateRequestId as t, createLogger as u, filterEnvVars as v, getEnvString as y };
975
+ //# sourceMappingURL=dist-CmfvOT-w.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dist-CmfvOT-w.js","names":["parts","LogLevelEnum","LogLevelEnum"],"sources":["../../shared/dist/env.js","../../shared/dist/logger/sanitize.js","../../shared/dist/git.js","../../shared/dist/interpreter-types.js","../../shared/dist/logger/canonical.js","../../shared/dist/logger/types.js","../../shared/dist/logger/logger.js","../../shared/dist/logger/trace-context.js","../../shared/dist/logger/index.js","../../shared/dist/shell-escape.js","../../shared/dist/sse.js","../../shared/dist/types.js","../../shared/dist/ws-types.js"],"sourcesContent":["/**\n * Safely extract a string value from an environment object\n *\n * @param env - Environment object with dynamic keys\n * @param key - The environment variable key to access\n * @returns The string value if present and is a string, undefined otherwise\n */\nexport function getEnvString(env, key) {\n const value = env?.[key];\n return typeof value === 'string' ? value : undefined;\n}\n/**\n * Filter environment variables object to only include string values.\n * Skips undefined, null, and non-string values.\n *\n * Use this when you only need the defined values (e.g., for per-command env\n * where undefined means \"don't override\").\n *\n * @param envVars - Object that may contain undefined values\n * @returns Clean object with only string values\n */\nexport function filterEnvVars(envVars) {\n const filtered = {};\n for (const [key, value] of Object.entries(envVars)) {\n if (value != null && typeof value === 'string') {\n filtered[key] = value;\n }\n }\n return filtered;\n}\n/**\n * Partition environment variables into values to set and keys to unset.\n *\n * - String values → toSet (will be exported)\n * - undefined/null → toUnset (will be unset)\n *\n * This enables idiomatic JS patterns where undefined means \"remove\":\n * ```typescript\n * await sandbox.setEnvVars({\n * API_KEY: 'new-key', // will be set\n * OLD_VAR: undefined, // will be unset\n * });\n * ```\n */\nexport function partitionEnvVars(envVars) {\n const toSet = {};\n const toUnset = [];\n for (const [key, value] of Object.entries(envVars)) {\n if (value != null && typeof value === 'string') {\n toSet[key] = value;\n }\n else {\n toUnset.push(key);\n }\n }\n return { toSet, toUnset };\n}\n","/**\n * Log-only sanitization helpers\n *\n * These functions redact sensitive values for logging output.\n * They MUST NOT be used to mutate command strings before execution.\n */\n/**\n * Sensitive query parameter names to redact from URLs.\n * Anchored to query string context ([?&]) to avoid matching path segments.\n * Value matching stops at & and common URL/command delimiters.\n */\nconst SENSITIVE_PARAMS = /([?&])(X-Amz-Credential|X-Amz-Signature|X-Amz-Security-Token|token|secret|password)=[^&\\s\"'`<>]*/gi;\n/**\n * Redact credentials from URLs for secure logging\n *\n * Replaces any credentials (username:password, tokens, etc.) embedded\n * in URLs with ****** to prevent sensitive data exposure in logs.\n * Works with URLs embedded in text.\n *\n * @param text - String that may contain URLs with credentials\n * @returns String with credentials redacted from any URLs\n */\nexport function redactCredentials(text) {\n // Scan for http(s):// URLs and redact any credentials found\n let result = text;\n let pos = 0;\n while (pos < result.length) {\n const httpPos = result.indexOf('http://', pos);\n const httpsPos = result.indexOf('https://', pos);\n let protocolPos = -1;\n let protocolLen = 0;\n if (httpPos === -1 && httpsPos === -1)\n break;\n if (httpPos !== -1 && (httpsPos === -1 || httpPos < httpsPos)) {\n protocolPos = httpPos;\n protocolLen = 7; // 'http://'.length\n }\n else {\n protocolPos = httpsPos;\n protocolLen = 8; // 'https://'.length\n }\n // Look for @ after the protocol\n const searchStart = protocolPos + protocolLen;\n const atPos = result.indexOf('@', searchStart);\n // Find where the URL ends (whitespace, quotes, or structural delimiters)\n let urlEnd = searchStart;\n while (urlEnd < result.length) {\n const char = result[urlEnd];\n if (/[\\s\"'`<>,;{}[\\]]/.test(char))\n break;\n urlEnd++;\n }\n if (atPos !== -1 && atPos < urlEnd) {\n result = `${result.substring(0, searchStart)}******${result.substring(atPos)}`;\n pos = searchStart + 6; // Move past '******'\n }\n else {\n pos = protocolPos + protocolLen;\n }\n }\n return result;\n}\n/**\n * Redact sensitive query parameters from URLs\n *\n * Strips X-Amz-Credential, X-Amz-Signature, X-Amz-Security-Token,\n * token, secret, and password query params from URLs. Returns\n * non-URL strings unchanged.\n *\n * @param input - String that may contain URLs with sensitive params\n * @returns String with sensitive params replaced by REDACTED\n */\nexport function redactSensitiveParams(input) {\n if (!input.includes('?') || !input.includes('='))\n return input;\n return input.replace(SENSITIVE_PARAMS, '$1$2=REDACTED');\n}\n/**\n * Redact sensitive data from a command string for logging\n *\n * Composes redactCredentials (URL credentials) and redactSensitiveParams\n * (presigned URL query params). For log values only — never mutate\n * command strings before execution.\n *\n * @param command - Command string to sanitize for logging\n * @returns Sanitized command string\n */\nexport function redactCommand(command) {\n return redactSensitiveParams(redactCredentials(command));\n}\n/**\n * Truncate a string for log output with a truncation indicator\n *\n * @param value - String to potentially truncate\n * @param maxLen - Maximum length before truncation (default 120)\n * @returns Object with truncated value and boolean flag\n */\nexport function truncateForLog(value, maxLen = 120) {\n if (value.length <= maxLen) {\n return { value, truncated: false };\n }\n const cutoff = Math.max(0, maxLen - 3);\n return { value: `${value.substring(0, cutoff)}...`, truncated: true };\n}\n","import { redactCommand } from './logger/sanitize.js';\n/**\n * Fallback repository name used when URL parsing fails\n */\nexport const FALLBACK_REPO_NAME = 'repository';\n/**\n * Extract repository name from a Git URL\n *\n * Supports multiple URL formats:\n * - HTTPS: https://github.com/user/repo.git → repo\n * - HTTPS without .git: https://github.com/user/repo → repo\n * - SSH: git@github.com:user/repo.git → repo\n * - GitLab/others: https://gitlab.com/org/project.git → project\n *\n * @param repoUrl - Git repository URL (HTTPS or SSH format)\n * @returns Repository name extracted from URL, or 'repository' as fallback\n */\nexport function extractRepoName(repoUrl) {\n // Try parsing as standard URL (https://, http://)\n try {\n const url = new URL(repoUrl);\n const pathParts = url.pathname.split('/');\n const lastPart = pathParts[pathParts.length - 1];\n if (lastPart) {\n return lastPart.replace(/\\.git$/, '');\n }\n }\n catch {\n // Not a standard URL, try SSH format\n }\n // For SSH URLs (git@github.com:user/repo.git), split by : and / to get last segment\n // Only process if the URL contains path delimiters\n if (repoUrl.includes(':') || repoUrl.includes('/')) {\n const segments = repoUrl.split(/[:/]/).filter(Boolean);\n const lastSegment = segments[segments.length - 1];\n if (lastSegment) {\n return lastSegment.replace(/\\.git$/, '');\n }\n }\n return FALLBACK_REPO_NAME;\n}\n/**\n * Sanitize data by redacting credentials from any strings\n * Recursively processes objects and arrays to ensure credentials are never leaked\n */\nexport function sanitizeGitData(data) {\n // Handle primitives\n if (typeof data === 'string') {\n return redactCommand(data);\n }\n if (data === null || data === undefined) {\n return data;\n }\n // Handle arrays\n if (Array.isArray(data)) {\n return data.map((item) => sanitizeGitData(item));\n }\n // Handle objects - recursively sanitize all fields\n if (typeof data === 'object') {\n const result = {};\n for (const [key, value] of Object.entries(data)) {\n result[key] = sanitizeGitData(value);\n }\n return result;\n }\n return data;\n}\n/**\n * Logger wrapper that automatically sanitizes git credentials\n */\nexport class GitLogger {\n baseLogger;\n constructor(baseLogger) {\n this.baseLogger = baseLogger;\n }\n sanitizeContext(context) {\n return context\n ? sanitizeGitData(context)\n : context;\n }\n sanitizeError(error) {\n if (!error)\n return error;\n // Create a new error with sanitized message and stack\n const sanitized = new Error(redactCommand(error.message));\n sanitized.name = error.name;\n if (error.stack) {\n sanitized.stack = redactCommand(error.stack);\n }\n // Preserve other enumerable properties\n const sanitizedRecord = sanitized;\n const errorRecord = error;\n for (const key of Object.keys(error)) {\n if (key !== 'message' && key !== 'stack' && key !== 'name') {\n sanitizedRecord[key] = sanitizeGitData(errorRecord[key]);\n }\n }\n return sanitized;\n }\n debug(message, context) {\n this.baseLogger.debug(message, this.sanitizeContext(context));\n }\n info(message, context) {\n this.baseLogger.info(message, this.sanitizeContext(context));\n }\n warn(message, context) {\n this.baseLogger.warn(message, this.sanitizeContext(context));\n }\n error(message, error, context) {\n this.baseLogger.error(message, this.sanitizeError(error), this.sanitizeContext(context));\n }\n child(context) {\n const sanitized = sanitizeGitData(context);\n const childLogger = this.baseLogger.child(sanitized);\n return new GitLogger(childLogger);\n }\n}\n","// Execution Result Container\nexport class Execution {\n code;\n context;\n /**\n * All results from the execution\n */\n results = [];\n /**\n * Accumulated stdout and stderr\n */\n logs = {\n stdout: [],\n stderr: []\n };\n /**\n * Execution error if any\n */\n error;\n /**\n * Execution count (for interpreter)\n */\n executionCount;\n constructor(code, context) {\n this.code = code;\n this.context = context;\n }\n /**\n * Convert to a plain object for serialization\n */\n toJSON() {\n return {\n code: this.code,\n logs: this.logs,\n error: this.error,\n executionCount: this.executionCount,\n results: this.results.map((result) => ({\n text: result.text,\n html: result.html,\n png: result.png,\n jpeg: result.jpeg,\n svg: result.svg,\n latex: result.latex,\n markdown: result.markdown,\n javascript: result.javascript,\n json: result.json,\n chart: result.chart,\n data: result.data\n }))\n };\n }\n}\n// Implementation of Result\nexport class ResultImpl {\n raw;\n constructor(raw) {\n this.raw = raw;\n }\n get text() {\n return this.raw.text || this.raw.data?.['text/plain'];\n }\n get html() {\n return this.raw.html || this.raw.data?.['text/html'];\n }\n get png() {\n return this.raw.png || this.raw.data?.['image/png'];\n }\n get jpeg() {\n return this.raw.jpeg || this.raw.data?.['image/jpeg'];\n }\n get svg() {\n return this.raw.svg || this.raw.data?.['image/svg+xml'];\n }\n get latex() {\n return this.raw.latex || this.raw.data?.['text/latex'];\n }\n get markdown() {\n return this.raw.markdown || this.raw.data?.['text/markdown'];\n }\n get javascript() {\n return this.raw.javascript || this.raw.data?.['application/javascript'];\n }\n get json() {\n return this.raw.json || this.raw.data?.['application/json'];\n }\n get chart() {\n return this.raw.chart;\n }\n get data() {\n return this.raw.data;\n }\n formats() {\n const formats = [];\n if (this.text)\n formats.push('text');\n if (this.html)\n formats.push('html');\n if (this.png)\n formats.push('png');\n if (this.jpeg)\n formats.push('jpeg');\n if (this.svg)\n formats.push('svg');\n if (this.latex)\n formats.push('latex');\n if (this.markdown)\n formats.push('markdown');\n if (this.javascript)\n formats.push('javascript');\n if (this.json)\n formats.push('json');\n if (this.chart)\n formats.push('chart');\n return formats;\n }\n}\n","import { redactCommand, truncateForLog } from './sanitize.js';\n/** Events that are low-value at info on success */\nconst DEBUG_ON_SUCCESS = new Set([\n 'session.create',\n 'session.destroy',\n 'file.read',\n 'file.write',\n 'file.delete',\n 'file.mkdir'\n]);\nexport function resolveLogLevel(payload, options) {\n if (payload.outcome === 'error')\n return 'error';\n if (options?.successLevel)\n return options.successLevel;\n if (payload.origin === 'internal')\n return 'debug';\n if (DEBUG_ON_SUCCESS.has(payload.event))\n return 'debug';\n return 'info';\n}\n/**\n * Sanitize an Error object by redacting sensitive data from message and stack.\n * Produces a copy so the caller's original Error is not mutated.\n */\nfunction sanitizeError(error) {\n if (!error)\n return undefined;\n const sanitized = new Error(redactCommand(error.message));\n sanitized.name = error.name;\n sanitized.stack = error.stack ? redactCommand(error.stack) : undefined;\n return sanitized;\n}\n/**\n * Sanitize and prepare payload fields for both message building and context emission.\n * Called once by logCanonicalEvent to avoid double-redaction.\n */\nfunction sanitizePayload(payload) {\n if (payload.command === undefined) {\n return { commandTruncated: false };\n }\n const redacted = redactCommand(payload.command);\n const { value, truncated } = truncateForLog(redacted);\n return { sanitizedCommand: value, commandTruncated: truncated };\n}\n/**\n * Build a human-readable canonical event message for dashboards and log viewers.\n *\n * Format: `{event} {outcome} {key_context} [— {reason}] ({durationMs}ms[, {sizeBytes}B])`\n *\n * The if/else chain for key context has implicit priority: command > path >\n * sessionId > port > repoUrl > pid. If a payload has multiple, only the\n * highest-priority one appears in the message. All fields are still present\n * as discrete queryable keys in the structured log context.\n */\nexport function buildMessage(payload, sanitizedCommand) {\n const { event } = payload;\n // version.check has its own format: no outcome, no duration\n if (event === 'version.check') {\n const parts = ['version.check'];\n if (payload.sdkVersion)\n parts.push(`sdk=${payload.sdkVersion}`);\n if (payload.containerVersion)\n parts.push(`container=${payload.containerVersion}`);\n if (payload.versionOutcome && payload.versionOutcome !== 'compatible') {\n parts.push(`(${payload.versionOutcome})`);\n }\n return parts.join(' ');\n }\n const parts = [event, payload.outcome];\n // Key context — highest priority field shown in message\n if (sanitizedCommand !== undefined) {\n parts.push(sanitizedCommand);\n }\n else if (payload.command !== undefined) {\n // Fallback for direct buildMessage calls without pre-sanitized command\n const redacted = redactCommand(payload.command);\n const { value } = truncateForLog(redacted);\n parts.push(value);\n }\n else if (payload.path !== undefined) {\n parts.push(payload.path);\n }\n else if (event.includes('session') && payload.sessionId !== undefined) {\n parts.push(payload.sessionId);\n }\n else if (payload.port !== undefined) {\n parts.push(String(payload.port));\n }\n else if (payload.repoUrl !== undefined) {\n let gitContext = payload.repoUrl;\n if (payload.branch !== undefined) {\n gitContext += ` ${payload.branch}`;\n }\n parts.push(gitContext);\n }\n else if (payload.pid !== undefined) {\n parts.push(String(payload.pid));\n }\n else if (payload.backupId !== undefined) {\n parts.push(payload.backupId);\n }\n else if (payload.repoPath !== undefined) {\n let gitContext = payload.repoPath;\n if (payload.branch !== undefined) {\n gitContext += ` branch=${payload.branch}`;\n }\n parts.push(gitContext);\n }\n else if (payload.mountsProcessed !== undefined) {\n let destroyContext = `${payload.mountsProcessed} mounts`;\n if (payload.mountFailures)\n destroyContext += `, ${payload.mountFailures} failed`;\n parts.push(destroyContext);\n }\n else if (payload.mountPath !== undefined) {\n parts.push(payload.mountPath);\n }\n // Error reason after em-dash\n if (payload.outcome === 'error') {\n if (payload.errorMessage !== undefined) {\n parts.push(`\\u2014 ${payload.errorMessage}`);\n }\n else if (payload.exitCode !== undefined) {\n parts.push(`\\u2014 exitCode=${payload.exitCode}`);\n }\n }\n // Duration suffix (and optional size)\n const durationSuffix = payload.sizeBytes !== undefined\n ? `(${payload.durationMs}ms, ${payload.sizeBytes}B)`\n : `(${payload.durationMs}ms)`;\n parts.push(durationSuffix);\n return parts.join(' ');\n}\n/**\n * Log a canonical event — the single entry point for all structured operational events.\n *\n * Sanitizes command fields once, builds the message, selects log level from\n * outcome, and emits a structured log entry with the full payload as context.\n */\nexport function logCanonicalEvent(logger, payload, options) {\n // Auto-derive errorMessage from error.message when not explicitly set,\n // then sanitize to prevent credential leaks (e.g., presigned URLs in error strings)\n const resolvedErrorMessage = payload.errorMessage ?? payload.error?.message;\n const sanitizedErrorMessage = resolvedErrorMessage\n ? redactCommand(resolvedErrorMessage)\n : undefined;\n const enrichedPayload = sanitizedErrorMessage !== undefined\n ? { ...payload, errorMessage: sanitizedErrorMessage }\n : payload;\n // Sanitize once, use for both message and context\n const { sanitizedCommand, commandTruncated } = sanitizePayload(enrichedPayload);\n const message = buildMessage(enrichedPayload, sanitizedCommand);\n // Build context from enriched payload, excluding the error object (passed separately)\n const context = {};\n for (const [key, value] of Object.entries(enrichedPayload)) {\n if (key === 'error')\n continue;\n context[key] = value;\n }\n // Apply sanitized command to context\n if (sanitizedCommand !== undefined) {\n context.command = sanitizedCommand;\n if (commandTruncated) {\n context.commandTruncated = true;\n }\n }\n const level = resolveLogLevel(enrichedPayload, options);\n if (level === 'error') {\n logger.error(message, sanitizeError(payload.error), context);\n }\n else if (level === 'warn') {\n logger.warn(message, context);\n }\n else if (level === 'debug') {\n logger.debug(message, context);\n }\n else {\n logger.info(message, context);\n }\n}\n","/**\n * Logger types for Cloudflare Sandbox SDK\n *\n * Provides structured, trace-aware logging across Worker, Durable Object, and Container.\n */\n/**\n * Log levels (from most to least verbose)\n */\nexport var LogLevel;\n(function (LogLevel) {\n LogLevel[LogLevel[\"DEBUG\"] = 0] = \"DEBUG\";\n LogLevel[LogLevel[\"INFO\"] = 1] = \"INFO\";\n LogLevel[LogLevel[\"WARN\"] = 2] = \"WARN\";\n LogLevel[LogLevel[\"ERROR\"] = 3] = \"ERROR\";\n})(LogLevel || (LogLevel = {}));\n","/**\n * Logger implementation\n */\nimport { LogLevel as LogLevelEnum } from './types.js';\n/**\n * ANSI color codes for terminal output\n */\nconst COLORS = {\n reset: '\\x1b[0m',\n debug: '\\x1b[36m', // Cyan\n info: '\\x1b[32m', // Green\n warn: '\\x1b[33m', // Yellow\n error: '\\x1b[31m', // Red\n dim: '\\x1b[2m' // Dim\n};\n/**\n * CloudflareLogger implements structured logging with support for\n * both JSON output (production) and pretty printing (development).\n */\nexport class CloudflareLogger {\n baseContext;\n minLevel;\n outputMode;\n /**\n * Create a new CloudflareLogger\n *\n * @param baseContext Base context included in all log entries\n * @param minLevel Minimum log level to output (default: INFO)\n * @param outputMode How log entries are formatted and emitted (default: 'structured')\n */\n constructor(baseContext, minLevel = LogLevelEnum.INFO, outputMode = 'structured') {\n this.baseContext = baseContext;\n this.minLevel = minLevel;\n this.outputMode = outputMode;\n }\n /**\n * Log debug-level message\n */\n debug(message, context) {\n if (this.shouldLog(LogLevelEnum.DEBUG)) {\n const logData = this.buildLogData('debug', message, context);\n this.output(console.log, logData);\n }\n }\n /**\n * Log info-level message\n */\n info(message, context) {\n if (this.shouldLog(LogLevelEnum.INFO)) {\n const logData = this.buildLogData('info', message, context);\n this.output(console.log, logData);\n }\n }\n /**\n * Log warning-level message\n */\n warn(message, context) {\n if (this.shouldLog(LogLevelEnum.WARN)) {\n const logData = this.buildLogData('warn', message, context);\n this.output(console.warn, logData);\n }\n }\n /**\n * Log error-level message\n */\n error(message, error, context) {\n if (this.shouldLog(LogLevelEnum.ERROR)) {\n const logData = this.buildLogData('error', message, context, error);\n this.output(console.error, logData);\n }\n }\n /**\n * Create a child logger with additional context\n */\n child(context) {\n return new CloudflareLogger({ ...this.baseContext, ...context }, this.minLevel, this.outputMode);\n }\n /**\n * Check if a log level should be output\n */\n shouldLog(level) {\n return level >= this.minLevel;\n }\n /**\n * Build log data object\n */\n buildLogData(level, message, context, error) {\n const logData = {\n level,\n message,\n ...this.baseContext,\n ...context,\n timestamp: new Date().toISOString()\n };\n // Add error details if provided\n if (error) {\n logData.error = {\n message: error.message,\n stack: error.stack,\n name: error.name\n };\n }\n return logData;\n }\n /**\n * Output log data using the configured output mode\n */\n output(consoleFn, data) {\n switch (this.outputMode) {\n case 'pretty':\n this.outputPretty(consoleFn, data);\n break;\n case 'json-line':\n this.outputJsonLine(consoleFn, data);\n break;\n case 'structured':\n this.outputStructured(consoleFn, data);\n break;\n }\n }\n /**\n * Output as JSON string (container stdout — parsed by Containers pipeline)\n */\n outputJsonLine(consoleFn, data) {\n consoleFn(JSON.stringify(data));\n }\n /**\n * Output as raw object (Workers/DOs — Workers Logs auto-indexes fields)\n */\n outputStructured(consoleFn, data) {\n consoleFn(data);\n }\n /**\n * Output as pretty-printed, colored text (development)\n *\n * Each log event is a single consoleFn() call so it appears as one entry\n * in the Cloudflare dashboard. Context is rendered inline as compact key=value pairs.\n *\n * Format: LEVEL [component] message trace=tr_... key=value key=value\n */\n outputPretty(consoleFn, data) {\n const { level, message: msg, timestamp, traceId, component, sandboxId, sessionId, processId, commandId, durationMs, serviceVersion, instanceId, error, ...rest } = data;\n const levelStr = String(level || 'INFO').toUpperCase();\n const levelColor = this.getLevelColor(levelStr);\n const componentBadge = component ? `[${component}]` : '';\n const timeStr = timestamp\n ? `${COLORS.dim}${new Date(timestamp).toISOString().substring(11, 23)}${COLORS.reset} `\n : '';\n let logLine = `${timeStr}${levelColor}${levelStr.padEnd(5)}${COLORS.reset} ${componentBadge} ${msg}`;\n // Append all context as compact key=value pairs on the same line\n const pairs = [];\n if (traceId)\n pairs.push(`trace=${String(traceId).substring(0, 12)}`);\n if (commandId)\n pairs.push(`cmd=${String(commandId).substring(0, 12)}`);\n if (sandboxId)\n pairs.push(`sandbox=${sandboxId}`);\n if (sessionId)\n pairs.push(`session=${String(sessionId).substring(0, 12)}`);\n if (processId)\n pairs.push(`proc=${processId}`);\n if (durationMs !== undefined)\n pairs.push(`dur=${durationMs}ms`);\n // Append remaining context fields inline\n for (const [key, value] of Object.entries(rest)) {\n if (value === undefined || value === null)\n continue;\n const v = typeof value === 'object'\n ? JSON.stringify(value)\n : this.sanitizePrettyValue(String(value));\n pairs.push(`${key}=${v}`);\n }\n // Append error info inline\n if (error && typeof error === 'object') {\n const errorObj = error;\n if (errorObj.name)\n pairs.push(`err.name=${this.sanitizePrettyValue(errorObj.name)}`);\n if (errorObj.message)\n pairs.push(`err.msg=${this.sanitizePrettyValue(errorObj.message)}`);\n if (errorObj.stack)\n pairs.push(`err.stack=${this.sanitizePrettyValue(errorObj.stack)}`);\n }\n if (pairs.length > 0) {\n logLine += ` ${COLORS.dim}${pairs.join(' ')}${COLORS.reset}`;\n }\n // Single consoleFn call = single log entry in the dashboard\n consoleFn(logLine);\n }\n /**\n * Collapse newlines so a single consoleFn() call stays on one line.\n * Cloudflare's log pipeline splits on literal newlines, which fragments\n * stack traces and multi-line error messages into separate entries.\n */\n sanitizePrettyValue(value) {\n return value.replace(/\\r/g, '\\\\r').replace(/\\n/g, '\\\\n');\n }\n /**\n * Get ANSI color code for log level\n */\n getLevelColor(level) {\n const levelLower = level.toLowerCase();\n switch (levelLower) {\n case 'debug':\n return COLORS.debug;\n case 'info':\n return COLORS.info;\n case 'warn':\n return COLORS.warn;\n case 'error':\n return COLORS.error;\n default:\n return COLORS.reset;\n }\n }\n}\n","/**\n * Trace context utilities for request correlation\n *\n * Trace IDs enable correlating logs across distributed components:\n * Worker → Durable Object → Container → back\n *\n * The trace ID is propagated via the X-Trace-Id HTTP header.\n */\n/**\n * Utility for managing trace context across distributed components\n */\n// biome-ignore lint/complexity/noStaticOnlyClass: Keep as class for namespace grouping and discoverability\nexport class TraceContext {\n /**\n * HTTP header name for trace ID propagation\n */\n static TRACE_HEADER = 'X-Trace-Id';\n /**\n * Generate a new trace ID\n *\n * Format: \"tr_\" + 16 random hex characters\n * Example: \"tr_7f3a9b2c4e5d6f1a\"\n *\n * @returns Newly generated trace ID\n */\n static generate() {\n // Use crypto.randomUUID() for randomness, extract 16 hex chars\n const randomHex = crypto.randomUUID().replace(/-/g, '').substring(0, 16);\n return `tr_${randomHex}`;\n }\n /**\n * Extract trace ID from HTTP request headers\n *\n * @param headers Request headers\n * @returns Trace ID if present, null otherwise\n */\n static fromHeaders(headers) {\n return headers.get(TraceContext.TRACE_HEADER);\n }\n /**\n * Create headers object with trace ID for outgoing requests\n *\n * @param traceId Trace ID to include\n * @returns Headers object with X-Trace-Id set\n */\n static toHeaders(traceId) {\n return { [TraceContext.TRACE_HEADER]: traceId };\n }\n /**\n * Get the header name used for trace ID propagation\n *\n * @returns Header name (\"X-Trace-Id\")\n */\n static getHeaderName() {\n return TraceContext.TRACE_HEADER;\n }\n}\n","/**\n * Logger module\n *\n * Provides structured, trace-aware logging with:\n * - Explicit logger passing via constructor injection\n * - Three output modes: structured (Workers/DOs), json-line (container), pretty (local dev)\n * - Environment auto-detection\n * - Log level configuration\n *\n * Usage:\n *\n * ```typescript\n * // Create a logger at entry point\n * const logger = createLogger({ component: 'sandbox-do', traceId: 'tr_abc123' });\n *\n * // Pass to classes via constructor\n * const service = new MyService(logger);\n *\n * // Create child loggers for additional context\n * const execLogger = logger.child({ commandId: 'cmd-456' });\n * execLogger.info('Operation started');\n * ```\n */\nimport { CloudflareLogger } from './logger.js';\nimport { TraceContext } from './trace-context.js';\nimport { LogLevel as LogLevelEnum } from './types.js';\nexport { buildMessage, logCanonicalEvent, resolveLogLevel } from './canonical.js';\nexport { CloudflareLogger } from './logger.js';\nexport { TraceContext } from './trace-context.js';\nexport { LogLevel as LogLevelEnum } from './types.js';\n/**\n * Create a no-op logger for testing\n *\n * Returns a logger that implements the Logger interface but does nothing.\n * Useful for tests that don't need actual logging output.\n *\n * @returns No-op logger instance\n *\n * @example\n * ```typescript\n * // In tests\n * const client = new HttpClient({\n * baseUrl: 'http://test.com',\n * logger: createNoOpLogger() // Optional - tests can enable real logging if needed\n * });\n * ```\n */\nexport function createNoOpLogger() {\n return {\n debug: () => { },\n info: () => { },\n warn: () => { },\n error: () => { },\n child: () => createNoOpLogger()\n };\n}\n/**\n * Create a new logger instance\n *\n * @param context Base context for the logger. Must include 'component'.\n * TraceId will be auto-generated if not provided.\n * @returns New logger instance\n *\n * @example\n * ```typescript\n * // In Durable Object\n * const logger = createLogger({\n * component: 'sandbox-do',\n * traceId: TraceContext.fromHeaders(request.headers) || TraceContext.generate(),\n * sandboxId: this.id\n * });\n *\n * // In Container\n * const logger = createLogger({\n * component: 'container',\n * traceId: TraceContext.fromHeaders(request.headers)!,\n * sessionId: this.id\n * });\n * ```\n */\nexport function createLogger(context) {\n const minLevel = getLogLevelFromEnv();\n const outputMode = getOutputMode(context.component);\n const baseContext = {\n ...context,\n traceId: context.traceId || TraceContext.generate(),\n component: context.component,\n serviceVersion: context.serviceVersion || getEnvVar('SANDBOX_VERSION') || undefined,\n instanceId: context.instanceId ||\n getEnvVar('HOSTNAME') ||\n getEnvVar('SANDBOX_INSTANCE_ID') ||\n undefined\n };\n return new CloudflareLogger(baseContext, minLevel, outputMode);\n}\n/**\n * Get log level from environment variable\n *\n * Checks SANDBOX_LOG_LEVEL env var, falls back to default based on environment.\n * Default: 'debug' for development, 'info' for production\n */\nfunction getLogLevelFromEnv() {\n const envLevel = getEnvVar('SANDBOX_LOG_LEVEL') || 'info';\n switch (envLevel.toLowerCase()) {\n case 'debug':\n return LogLevelEnum.DEBUG;\n case 'info':\n return LogLevelEnum.INFO;\n case 'warn':\n return LogLevelEnum.WARN;\n case 'error':\n return LogLevelEnum.ERROR;\n default:\n // Invalid level, fall back to info\n return LogLevelEnum.INFO;\n }\n}\n/**\n * Determine output mode based on component and environment:\n * - SANDBOX_LOG_FORMAT=pretty → 'pretty' for all components (local wrangler dev)\n * - Container/Executor without pretty → 'json-line' (Bun stdout → Containers pipeline)\n * - Everything else without pretty → 'structured' (Workers/DOs → Workers Logs)\n *\n * In local dev, setting SANDBOX_LOG_FORMAT=pretty gives readable terminal\n * output on both the DO side and container side. In production (where the\n * var isn't set), DOs emit structured objects and containers emit single-line\n * JSON — both queryable by their respective observability pipelines.\n */\nfunction getOutputMode(component) {\n const format = getEnvVar('SANDBOX_LOG_FORMAT');\n if (format?.toLowerCase() === 'pretty') {\n return 'pretty';\n }\n if (component === 'container' || component === 'executor') {\n return 'json-line';\n }\n return 'structured';\n}\n/**\n * Get environment variable value\n *\n * Supports both Node.js (process.env) and Bun (Bun.env)\n */\nfunction getEnvVar(name) {\n // Try process.env first (Node.js / Bun)\n if (typeof process !== 'undefined' && process.env) {\n return process.env[name];\n }\n // Try Bun.env (Bun runtime)\n if (typeof Bun !== 'undefined') {\n const bunEnv = Bun.env;\n if (bunEnv) {\n return bunEnv[name];\n }\n }\n return undefined;\n}\n","/**\n * Escapes a string for safe use in shell commands using POSIX single-quote escaping.\n * Prevents command injection by wrapping the string in single quotes and escaping\n * any single quotes within the string.\n */\nexport function shellEscape(str) {\n return `'${str.replace(/'/g, \"'\\\\''\")}'`;\n}\n","/**\n * Shared SSE parsing utilities.\n *\n * Parses SSE frames from arbitrary text chunks while preserving partial state\n * across chunk boundaries.\n */\n/**\n * Parse SSE frames from a buffer.\n *\n * Returns parsed events, remaining unparsed text, and the current partial event\n * so callers can continue parsing on the next chunk.\n */\nexport function parseSSEFrames(buffer, currentEvent = { data: [] }) {\n const events = [];\n let i = 0;\n while (i < buffer.length) {\n const newlineIndex = buffer.indexOf('\\n', i);\n if (newlineIndex === -1)\n break;\n const rawLine = buffer.substring(i, newlineIndex);\n const line = rawLine.endsWith('\\r') ? rawLine.slice(0, -1) : rawLine;\n i = newlineIndex + 1;\n if (line === '' && currentEvent.data.length > 0) {\n events.push({\n event: currentEvent.event,\n data: currentEvent.data.join('\\n')\n });\n currentEvent = { data: [] };\n continue;\n }\n if (line.startsWith('event:')) {\n const value = line.startsWith('event: ')\n ? line.substring(7)\n : line.substring(6);\n currentEvent.event = value;\n continue;\n }\n if (line.startsWith('data:')) {\n const value = line.startsWith('data: ')\n ? line.substring(6)\n : line.substring(5);\n currentEvent.data.push(value);\n }\n }\n return {\n events,\n remaining: buffer.substring(i),\n currentEvent\n };\n}\n","/**\n * Check if a process status indicates the process has terminated\n */\nexport function isTerminalStatus(status) {\n return (status === 'completed' ||\n status === 'failed' ||\n status === 'killed' ||\n status === 'error');\n}\n// Type guards for runtime validation\nexport function isExecResult(value) {\n return (value &&\n typeof value.success === 'boolean' &&\n typeof value.exitCode === 'number' &&\n typeof value.stdout === 'string' &&\n typeof value.stderr === 'string');\n}\nexport function isProcess(value) {\n return (value &&\n typeof value.id === 'string' &&\n typeof value.command === 'string' &&\n typeof value.status === 'string');\n}\nexport function isProcessStatus(value) {\n return [\n 'starting',\n 'running',\n 'completed',\n 'failed',\n 'killed',\n 'error'\n ].includes(value);\n}\n// Re-export interpreter types for convenience\nexport { Execution, ResultImpl } from './interpreter-types';\n","/**\n * WebSocket transport protocol types\n *\n * Enables multiplexing HTTP-like requests over a single WebSocket connection.\n * This reduces sub-request count when running inside Workers/Durable Objects.\n *\n * Protocol:\n * - Client sends WSRequest messages\n * - Server responds with WSResponse messages (matched by id)\n * - For streaming endpoints, server sends multiple WSStreamChunk messages\n * followed by a final WSResponse\n */\n/**\n * Type guard for WSRequest\n *\n * Note: Only validates the discriminator field (type === 'request').\n * Does not validate other required fields (id, method, path).\n * Use for routing messages; trust TypeScript for field validation.\n */\nexport function isWSRequest(msg) {\n return (typeof msg === 'object' &&\n msg !== null &&\n 'type' in msg &&\n msg.type === 'request');\n}\n/**\n * Type guard for WSResponse\n *\n * Note: Only validates the discriminator field (type === 'response').\n */\nexport function isWSResponse(msg) {\n return (typeof msg === 'object' &&\n msg !== null &&\n 'type' in msg &&\n msg.type === 'response');\n}\n/**\n * Type guard for WSStreamChunk\n *\n * Note: Only validates the discriminator field (type === 'stream').\n */\nexport function isWSStreamChunk(msg) {\n return (typeof msg === 'object' &&\n msg !== null &&\n 'type' in msg &&\n msg.type === 'stream');\n}\n/**\n * Type guard for WSError\n *\n * Note: Only validates the discriminator field (type === 'error').\n */\nexport function isWSError(msg) {\n return (typeof msg === 'object' &&\n msg !== null &&\n 'type' in msg &&\n msg.type === 'error');\n}\n/**\n * Generate a unique request ID\n */\nexport function generateRequestId() {\n return `ws_${Date.now()}_${Math.random().toString(36).substring(2, 10)}`;\n}\n"],"mappings":";;;;;;;;AAOA,SAAgB,aAAa,KAAK,KAAK;CACnC,MAAM,QAAQ,MAAM;AACpB,QAAO,OAAO,UAAU,WAAW,QAAQ;;;;;;;;;;;;AAY/C,SAAgB,cAAc,SAAS;CACnC,MAAM,WAAW,EAAE;AACnB,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,QAAQ,CAC9C,KAAI,SAAS,QAAQ,OAAO,UAAU,SAClC,UAAS,OAAO;AAGxB,QAAO;;;;;;;;;;;;;;;;AAgBX,SAAgB,iBAAiB,SAAS;CACtC,MAAM,QAAQ,EAAE;CAChB,MAAM,UAAU,EAAE;AAClB,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,QAAQ,CAC9C,KAAI,SAAS,QAAQ,OAAO,UAAU,SAClC,OAAM,OAAO;KAGb,SAAQ,KAAK,IAAI;AAGzB,QAAO;EAAE;EAAO;EAAS;;;;;;;;;;;;;;;;AC5C7B,MAAM,mBAAmB;;;;;;;;;;;AAWzB,SAAgB,kBAAkB,MAAM;CAEpC,IAAI,SAAS;CACb,IAAI,MAAM;AACV,QAAO,MAAM,OAAO,QAAQ;EACxB,MAAM,UAAU,OAAO,QAAQ,WAAW,IAAI;EAC9C,MAAM,WAAW,OAAO,QAAQ,YAAY,IAAI;EAChD,IAAI,cAAc;EAClB,IAAI,cAAc;AAClB,MAAI,YAAY,MAA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