snap
The top-level snap key contains set of options instructing electron-builder on how it should build Snap packages for Linux.
What is Snap?
Snap is a universal Linux packaging format developed by Canonical (Ubuntu). Snap packages are self-contained, install on most Linux distributions, and are distributed through the Snap Store. Key characteristics:
- Sandboxed by default — confined to declared interfaces
- Automatic updates — the Snap daemon (
snapd) handles updates silently - Cross-distro — works on Ubuntu, Fedora, Debian, Arch, and more (with snapd installed)
- Ubuntu-primary — snapd ships by default on Ubuntu; other distros require manual install
Snap vs. AppImage vs. Flatpak
| Aspect | Snap | AppImage | Flatpak |
|---|---|---|---|
| Sandboxed | Yes (default) | No | Yes |
| Auto-update | Via Snap Store | Via AppImageUpdate | Via Flathub |
| Offline install | Yes (--dangerous) | Yes | Yes |
| Distro support | Ubuntu-native, others need snapd | Universal | Universal |
| Store | Snap Store | N/A | Flathub |
| electron-updater | Not needed (use Snap Store) | Needed | Not needed (Flathub) |
| electron-builder support | Full | Full | Full |
Build Requirements
Building Snap packages requires a Linux environment (or Docker).
Confinement
The confinement option controls how strictly the snap is sandboxed:
| Confinement | Description | Use Case |
|---|---|---|
strict | Full sandbox, access via declared interfaces only | Production apps (required for Snap Store) |
devmode | No sandbox, all access allowed | Development and debugging only |
classic | Unrestricted access (like a regular binary) | CLI tools that need full system access |
snap:
confinement: strict # required for Snap Store submission
Snap Store requires manual review and approval for classic confinement. Electron apps typically use strict with appropriate interface plugs.
Base
The base option selects the Ubuntu runtime your snap is built against. This determines which Ubuntu packages are available and the minimum snapd version required:
| Base | Ubuntu Version | snapd Requirement | Status |
|---|---|---|---|
core | Ubuntu 16.04 | Any | Legacy |
core20 | Ubuntu 20.04 LTS | snapd 2.44+ | Stable |
core22 | Ubuntu 22.04 LTS | snapd 2.58+ | Recommended |
core24 | Ubuntu 24.04 LTS | snapd 2.63+ | Stable |
snap:
base: core22 # recommended as of 2024
Interface Plugs
Electron apps require several interface plugs to function properly in strict confinement:
snap:
plugs:
- browser-support # required for Chromium/Electron rendering
- network # network access
- network-bind # listen on ports
- home # read/write home directory
- removable-media # USB drives, external storage
- audio-playback # sound output
- audio-record # microphone
- opengl # GPU acceleration
- desktop # X11/Wayland display
- desktop-legacy # GTK legacy theming
- unity7 # Unity/X11 appindicator
- x11 # X11 display
- wayland # Wayland display
- gsettings # GNOME settings (theming, fonts)
- password-manager-service # system keychain access
Start with only the plugs you actually need. Unnecessary plugs may slow Snap Store review. At minimum, browser-support, network, desktop, and desktop-legacy are needed for most Electron apps.
Custom plug configuration:
snap:
plugs:
- name: browser-support
allow-sandbox: true
- network
- home
Stage Packages
Include Ubuntu system packages in your snap if your app depends on libraries not available in the base:
snap:
stagePackages:
- libusb-1.0-0 # USB device access
- libsecret-1-0 # Secret Service (keychain)
- libappindicator3-1 # System tray (deprecated but widely needed)
Grade
snap:
grade: stable # or "devel"
The stable grade is required for release to the stable and candidate channels in the Snap Store. Use devel during development.
Environment Variables
Pass environment variables into the snap runtime:
snap:
environment:
TMPDIR: $XDG_RUNTIME_DIR
NODE_ENV: production
Wayland Support
Enable native Wayland rendering (instead of XWayland compatibility):
snap:
allowNativeWayland: true
This requires the wayland plug.
Auto-Start on Login
snap:
autoStart: true # Default: false
Adds a systemd user service that starts the app after the user logs in.
Snap Layouts
Use layouts to give the snap access to restricted paths:
snap:
layout:
/usr/share/alsa:
bind: $SNAP/usr/share/alsa
/etc/asound.conf:
bind-file: $SNAP/etc/asound.conf
Parts
The appPartStage option controls which files are included from the main app part:
snap:
appPartStage:
- -usr/share/doc
- -usr/share/man
Publishing to the Snap Store
- Create an account at snapcraft.io, register your snap name, and install the
snapcraftCLI — see Publishing to the Snap Store - Configure publishing in your electron-builder config:
publish:
provider: snapStore
repo: myapp # your registered snap name
channels:
- stable
- Build and publish:
electron-builder --linux snap --publish always
Channel Strategy
| Channel | Purpose |
|---|---|
edge | Latest development builds (auto-published from CI) |
beta | Beta testing builds |
candidate | Release candidates |
stable | Production releases |
Local Testing
Install a locally built snap without the Snap Store:
sudo snap install --dangerous dist/myapp_1.0.0_amd64.snap
Run and check logs:
myapp
journalctl --user -xe | grep myapp
To uninstall: sudo snap remove myapp
Debugging
Enable verbose electron-builder output:
DEBUG=electron-builder electron-builder --linux snap
For snap runtime issues, check confinement denials:
snap run --shell myapp
# Inside the snap shell, test what's accessible
Configuration
Interface: SnapOptions
Extends
Properties
after?
readonlyoptionalafter?:string[] |null
Specifies any parts that should be built before this part.
Defaults to ["desktop-gtk2""].
If list contains default, it will be replaced to default list, so, ["default", "foo"] can be used to add custom parts foo in addition to defaults.
allowNativeWayland?
readonlyoptionalallowNativeWayland?:boolean|null
Allow running the program with native wayland support with --ozone-platform=wayland. Disabled by default because of this issue in older Electron/Snap versions: https://github.com/electron-userland/electron-builder/issues/4007
appPartStage?
readonlyoptionalappPartStage?:string[] |null
Specifies which files from the app part to stage and which to exclude. Individual files, directories, wildcards, globstars, and exclusions are accepted. See Snapcraft filesets to learn more about the format.
The defaults can be found in snap.ts.
artifactName?
readonlyoptionalartifactName?:string|null
The artifact file name template.
Inherited from
TargetSpecificOptions.artifactName
assumes?
readonlyoptionalassumes?:string|string[] |null
The list of features that must be supported by the core in order for this snap to install.
autoStart?
readonlyoptionalautoStart?:boolean
Whether or not the snap should automatically start on login.
Default
false
base?
readonlyoptionalbase?:string|null
A snap of type base to be used as the execution environment for this snap. Examples: core, core18, core20, core22. Defaults to core20
buildPackages?
readonlyoptionalbuildPackages?:string[] |null
The list of debian packages needs to be installed for building this snap.
category?
readonlyoptionalcategory?:string|null
The application category.
Inherited from
compression?
readonlyoptionalcompression?:"xz"|"lzo"|null
Sets the compression type for the snap. Can be xz, lzo, or null.
confinement?
readonlyoptionalconfinement?:"devmode"|"strict"|"classic"|null
The type of confinement supported by the snap.
Default
strict
description?
readonlyoptionaldescription?:string|null
As description from application package.json, but allows you to specify different for Linux.
Inherited from
CommonLinuxOptions.description
desktop?
readonlyoptionaldesktop?:LinuxDesktopFile|null
The Desktop file
Inherited from
environment?
readonlyoptionalenvironment?: {[key:string]:string; } |null
The custom environment. Defaults to {"TMPDIR: "$XDG_RUNTIME_DIR"}. If you set custom, it will be merged with default.
executableArgs?
readonlyoptionalexecutableArgs?:string[] |null
The executable parameters. Pass to executableName
Inherited from
CommonLinuxOptions.executableArgs
grade?
readonlyoptionalgrade?:"devel"|"stable"|null
The quality grade of the snap. It can be either devel (i.e. a development version of the snap, so not to be published to the “stable” or “candidate” channels) or “stable” (i.e. a stable release or release candidate, which can be released to all channels).
Default
stable
hooks?
readonlyoptionalhooks?:string|null
The hooks directory, relative to build (build resources directory).
Default
build/snap-hooks
layout?
readonlyoptionallayout?: {[key:string]:object; } |null
Specifies any files to make accessible from locations such as /usr, /var, and /etc. See snap layouts to learn more.
mimeTypes?
readonlyoptionalmimeTypes?:string[] |null
The mime types in addition to specified in the file associations. Use it if you don't want to register a new mime type, but reuse existing.
Inherited from
plugs?
readonlyoptionalplugs?:PlugDescriptor| (string|PlugDescriptor)[] |null
The list of plugs.
Defaults to ["desktop", "desktop-legacy", "home", "x11", "wayland", "unity7", "browser-support", "network", "gsettings", "audio-playback", "pulseaudio", "opengl"].
If list contains default, it will be replaced to default list, so, ["default", "foo"] can be used to add custom plug foo in addition to defaults.
Additional attributes can be specified using object instead of just name of plug:
[
{
"browser-sandbox": {
"interface": "browser-support",
"allow-sandbox": true
},
},
"another-simple-plug-name"
]
publish?
optionalpublish?:Publish
Inherited from
slots?
readonlyoptionalslots?:PlugDescriptor| (string|SlotDescriptor)[] |null
The list of slots.
Additional attributes can be specified using object instead of just name of slot:
[
{
"mpris": {
"name": "chromium"
},
}
]
In case you want your application to be a compliant MPris player, you will need to definie
The mpris slot with "chromium" name.
This electron has it [hardcoded](https://source.chromium.org/chromium/chromium/src/+/master:components/system_media_controls/linux/system_media_controls_linux.cc;l=51;bpv=0;bpt=1),
and we need to pass this name so snap [will allow it](https://forum.snapcraft.io/t/unable-to-use-mpris-interface/15360/7) in strict confinement.
***
### stagePackages?
> `readonly` `optional` **stagePackages?**: `string`[] \| `null`
The list of Ubuntu packages to use that are needed to support the `app` part creation. Like `depends` for `deb`.
Defaults to `["libnspr4", "libnss3", "libxss1", "libappindicator3-1", "libsecret-1-0"]`.
If list contains `default`, it will be replaced to default list, so, `["default", "foo"]` can be used to add custom package `foo` in addition to defaults.
***
### summary?
> `readonly` `optional` **summary?**: `string` \| `null`
The 78 character long summary. Defaults to [productName](https://www.electron.build/configuration#productname).
***
### synopsis?
> `readonly` `optional` **synopsis?**: `string` \| `null`
The [short description](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Description).
#### Inherited from
[`CommonLinuxOptions`](/docs/api/app-builder-lib.Interface.CommonLinuxOptions).[`synopsis`](/docs/api/app-builder-lib.Interface.CommonLinuxOptions#synopsis)
***
### title?
> `readonly` `optional` **title?**: `string` \| `null`
An optional title for the snap, may contain uppercase letters and spaces. Defaults to `productName`. See [snap format documentation](https://snapcraft.io/docs/snap-format).
***
### useTemplateApp?
> `readonly` `optional` **useTemplateApp?**: `boolean`
Whether to use template snap. Defaults to `true` if `stagePackages` not specified.