Repository: mastra-ai/mastra
File: workspaces/e2b/src/sandbox/index.ts (TypeScript)

Code before:
const SAFE_MOUNT_PATH = /^\/[a-zA-Z0-9_.\-/]+$/;

function validateMountPath(mountPath: string): void {
  if (!SAFE_MOUNT_PATH.test(mountPath)) {
    throw new Error(
      `Invalid mount path: ${mountPath}. Must be an absolute path with alphanumeric, dash, dot, underscore, or slash characters only.`,
    );
  }
}

/** Allowlist for marker filenames from ls output — e.g. "mount-abc123" */
const SAFE_MARKER_NAME = /^mount-[a-z0-9]+$/;

// =============================================================================
// E2B Sandbox Options
// =============================================================================

/**
 * Runtime types supported by E2B.
 */
export type SandboxRuntime = 'node' | 'python' | 'bash' | 'ruby' | 'go' | 'rust' | 'java' | 'cpp' | 'r';

/**
 * E2B sandbox provider configuration.
 */
export interface E2BSandboxOptions extends Omit<MastraSandboxOptions, 'name'> {
  /** Unique identifier for this sandbox instance */
  id?: string;
  /**
   * Sandbox template specification.
   *
   * - `string` - Use an existing template by ID
   * - `TemplateBuilder` - Use a custom template (e.g., from `createMountableTemplate()`)
   * - `(base) => base.aptInstall([...])` - Customize the default mountable template
   *
   * If not provided and mounting is used, a default template with s3fs will be built.
   * For best performance, pre-build your template and use the template ID.
   *
   * @see createDefaultMountableTemplate
   */
  template?: TemplateSpec;
  /** Execution timeout in milliseconds
   *
   * @default 300_000 // 5 minutes
   */
  timeout?: number;
  /** Environment variables to set in the sandbox */
  env?: Record<string, string>;
  /** Custom metadata */
  metadata?: Record<string, unknown>;
  /** Supported runtimes (default: ['node', 'python', 'bash']) */

Review comment (suggestion):
```suggestion
export interface E2BSandboxOptions extends MastraSandboxOptions {
```

Code after:
const SAFE_MOUNT_PATH = /^\/[a-zA-Z0-9_.\-/]+$/;

function validateMountPath(mountPath: string): void {
  if (!SAFE_MOUNT_PATH.test(mountPath)) {
    throw new Error(
      `Invalid mount path: ${mountPath}. Must be an absolute path with alphanumeric, dash, dot, underscore, or slash characters only.`,
    );
  }
}

/** Allowlist for marker filenames from ls output — e.g. "mount-abc123" */
const SAFE_MARKER_NAME = /^mount-[a-z0-9]+$/;

// =============================================================================
// E2B Sandbox Options
// =============================================================================

/**
 * Runtime types supported by E2B.
 */
export type SandboxRuntime = 'node' | 'python' | 'bash' | 'ruby' | 'go' | 'rust' | 'java' | 'cpp' | 'r';

/**
 * E2B sandbox provider configuration.
 */
export interface E2BSandboxOptions extends MastraSandboxOptions {
  /** Unique identifier for this sandbox instance */
  id?: string;
  /**
   * Sandbox template specification.
   *
   * - `string` - Use an existing template by ID
   * - `TemplateBuilder` - Use a custom template (e.g., from `createMountableTemplate()`)
   * - `(base) => base.aptInstall([...])` - Customize the default mountable template
   *
   * If not provided and mounting is used, a default template with s3fs will be built.
   * For best performance, pre-build your template and use the template ID.
   *
   * @see createDefaultMountableTemplate
   */
  template?: TemplateSpec;
  /** Execution timeout in milliseconds
   *
   * @default 300_000 // 5 minutes
   */
  timeout?: number;
  /** Environment variables to set in the sandbox */
  env?: Record<string, string>;
  /** Custom metadata */
  metadata?: Record<string, unknown>;
  /** Supported runtimes (default: ['node', 'python', 'bash']) */