AppBundle Documentation & Implementation Details Labs

runtime.md

by xplshn 2025/05/24

AppBundle Runtime Execution

This document describes how the AppBundle runtime operates, including how it reads its own information, extracts static tools, determines environment variables, and handles runtime flags.

Execution Flow

When an AppBundle is executed, the runtime performs the following steps:

  1. Read Runtime Information:

    • The runtime reads the .pbundle_runtime_info section from the ELF file, which contains CBOR-encoded metadata.
    • This section includes:
      • AppBundleID: A unique identifier for the AppBundle. (e.g: “com.brave.Browser-xplshn-2025-05-19”. You’re not forced to follow this format, but if you do, you can create a dbin repository that countains your AppBundle by using our appstream-helper tool. $NAME-$MAINTAINER-$DATE or preferably: $APPSTREAM_ID-$MAINTAINER-$DATE, so that you don’t have to include an AppStream file within the AppDir for appstream-helper to get metadata from it)
      • PelfVersion: The version of the pelf tool used to create the AppBundle.
      • HostInfo: System information from uname -mrsp(v) of the build machine.
      • FilesystemType: Either “dwarfs” or “squashfs”.
      • Hash: A hash of the filesystem image for integrity verification.
      • DisableRandomWorkDir: A boolean indicating whether to use a fixed working directory.
      • MountOrExtract: A uint8 value (0–3) specifying the run behavior (see below).
    • The runtime uses this information to configure its behavior and locate the filesystem image.
  2. Extract Static Tools:

    • The runtime accesses the static tools required for mounting or extracting the filesystem (e.g., dwarfs, dwarfsextract, squashfuse, unsquashfs).
    • The handling of static tools depends on the build mode:
      • noEmbed Edition: The tools are embedded in the .pbundle_static_tools ELF section as a ZSTD-compressed tar archive. The runtime determines the filesystem mounting and extraction commands at runtime, extracts the needed files from this archive to a temporary directory (cfg.staticToolsDir), and uses them to either mount or extract the filesystem.
      • Embed Edition: The tools are embedded directly in the binary using Go’s embed package, without compression. The runtime accesses these tools directly from the embedded filesystem, without needing to extract a compressed archive.
  3. Exported Env Variables:

    • The runtime sets up several environment variables to facilitate execution:
      • HOME: If a portable home directory (.AppBundleID.home) exists in the same directory as the AppBundle, it is used as $HOME.
      • XDG_DATA_HOME: If a portable share directory (.AppBundleID.share) exists, it is used as $XDG_DATA_HOME.
      • XDG_CONFIG_HOME: If a portable config directory (.AppBundleID.config) exists, it is used as $XDG_CONFIG_HOME.
      • APPDIR: Set to the mount or extraction directory
      • SELF: The absolute path to the AppBundle executable.
      • ARGV0: The basename of $SELF
      • PATH: Augmented to include the AppBundle’s bin directory and the directory containing the static tools.
  4. Mount or Extract Filesystem:

    • The runtime decides whether to mount or extract the filesystem image based on the MountOrExtract value:
      • 0: Mounts the filesystem using FUSE (e.g., dwarfs or squashfuse) and fails if FUSE is unavailable.
      • 1: Extracts the filesystem to a temporary directory (usually in tmpfs) and runs from there.
      • 2: Attempts to mount with FUSE; falls back to extraction if FUSE is unavailable.
      • 3: Similar to 2, but only falls back to extraction if the AppBundle is smaller than 350MB.
  5. Execute the Application:

    • The runtime executes the AppRun script within the AppDir.
    • If a specific command is provided via --pbundle_link, the runtime executes that command within the AppBundle’s environment, instead of executing the AppRun.

Runtime Flags

The AppBundle runtime supports several command-line flags to modify its behavior:

Notes