@penguinharness/sandbox-wsl · plugins/sandbox-wsl/src/index.ts:365

SandboxWsl

component

No JSDoc comment in source yet.

API

@Component({
  contributes: {
    // How the Plugins page shows this backend (read from ifaces.json, never by booting it).
    "PluginLibraryModule.cards": [
      {
        id: "sandbox-wsl.card",
        title: "Windows Sandbox",
        titleZh: "Windows 沙箱",
        descriptionZh:
          "PenguinHarness 在 Windows 上的 WSL 沙箱后端:命令在专用的 WSL2 发行版中经 bubblewrap 运行,并关闭 Windows 互操作。",
        shortDescription: "Windows: run commands in a confined WSL2 distro.",
        shortDescriptionZh: "Windows:在受限的 WSL2 发行版中运行命令。",
        category: "sandbox",
        icon: "icon.svg",
        preinstall: false,
      },
    ],
    "SandboxModule.providers": [
      {
        id: "sandbox-wsl.provider",
        name: "penguin-wsl",
        dimensions: ["fs-write", "network", "mask-paths", "closed-temp"],
        defaultFor: ["win32"],
      },
    ],
    "PluginConfigProvider.groups": [
      {
        id: "sandbox-wsl",
        title: "WSL",
        properties: {
          exposeWindowsDrives: {
            type: "boolean",
            title: "Show Windows drives read-only",
            titleZh: "以只读方式显示 Windows 磁盘",
            description:
              "Off: a confined command sees only its Workspace under /mnt. On: every Windows drive is visible read-only, your profile included.",
            descriptionZh:
              "关闭:被隔离的命令在 /mnt 下只能看到自己的工作区。打开:所有 Windows 磁盘以只读方式可见,包括你的用户目录。",
            default: false,
          },
          base: {
            type: "enum",
            title: "Base Linux",
            titleZh: "基础 Linux",
            description:
              "What the sandbox distro is built from. Ubuntu is the ordinary Linux most tools, wheels and prebuilt binaries expect. Alpine downloads about a tenth as much, but it is musl: some native npm modules, pip wheels and downloaded binaries do not run on it.",
            descriptionZh:
              "沙盒发行版基于哪个 Linux。Ubuntu 是绝大多数工具、wheel 与预编译二进制所预期的常规 Linux;Alpine 的下载量只有前者的十分之一左右,但它用 musl:部分原生 npm 模块、pip wheel 与预编译二进制无法运行。",
            options: [
              {
                value: "ubuntu",
                title: "Ubuntu 24.04 LTS (about 30 MB)",
                titleZh: "Ubuntu 24.04 LTS(约 30 MB)",
              },
              {
                value: "alpine",
                title: "Alpine (about 4 MB, musl)",
                titleZh: "Alpine(约 4 MB,musl)",
              },
            ],
            default: "ubuntu",
          },
          packages: {
            type: "list",
            title: "Packages",
            titleZh: "软件包",
            description:
              "Packages Initialize installs besides bubblewrap, one per line (for example nodejs, npm, python3). They are apt packages on Ubuntu and apk packages on Alpine. Windows toolchains cannot run inside the sandbox.",
            descriptionZh:
              "初始化时除 bubblewrap 外安装的软件包,每行一个(例如 nodejs、npm、python3)。Ubuntu 上是 apt 包,Alpine 上是 apk 包。Windows 工具链无法在沙盒内运行。",
            default: ["git", "curl", "nodejs"],
            pattern: "^[a-z0-9][a-z0-9._+-]*$",
            patternErrorMessage: "must be package names",
          },
          mirror: {
            type: "string",
            title: "Package mirror",
            titleZh: "软件包镜像",
            description:
              "Where the packages come from, empty for the official archive: an Ubuntu mirror such as https://mirrors.tuna.tsinghua.edu.cn/ubuntu, or an Alpine one such as https://mirrors.tuna.tsinghua.edu.cn/alpine. The base rootfs itself always comes from the distribution's own site.",
            descriptionZh:
              "软件包的下载地址,留空即用官方源:Ubuntu 镜像如 https://mirrors.tuna.tsinghua.edu.cn/ubuntu,Alpine 镜像如 https://mirrors.tuna.tsinghua.edu.cn/alpine。基础 rootfs 始终从发行版官方站点下载。",
            placeholder: "https://mirrors.tuna.tsinghua.edu.cn/ubuntu",
            pattern: "^https?://\\S+$",
            patternErrorMessage: "must be an http(s) URL",
          },
          distro: {
            type: "string",
            title: "Distro name",
            titleZh: "发行版名称",
            description: "The WSL distro this backend creates and runs commands in.",
            descriptionZh: "本后端创建并在其中执行命令的 WSL 发行版。",
            default: "penguin-sandbox",
            pattern: "^[A-Za-z0-9][A-Za-z0-9._-]*$",
            patternErrorMessage: "may use letters, digits, dot, dash and underscore",
          },
        },
      },
    ],
  },
})
export class SandboxWsl {
  @Use() private readonly config!: WslConfigReader;
  @Bind("sandbox-wsl.provider") provider!: SandboxProviderSource;
  setup();
}

Dependencies & Wiring

Extracted from class decorators
@Userequires (1)
@Bindbinds (1)
provider → sandbox-wsl.provider: SandboxProviderSource

Contributes

{
  "PluginLibraryModule.cards": [
    {
      "id": "sandbox-wsl.card",
      "title": "Windows Sandbox",
      "titleZh": "Windows 沙箱",
      "descriptionZh": "PenguinHarness 在 Windows 上的 WSL 沙箱后端:命令在专用的 WSL2 发行版中经 bubblewrap 运行,并关闭 Windows 互操作。",
      "shortDescription": "Windows: run commands in a confined WSL2 distro.",
      "shortDescriptionZh": "Windows:在受限的 WSL2 发行版中运行命令。",
      "category": "sandbox",
      "icon": "icon.svg",
      "preinstall": false
    }
  ],
  "SandboxModule.providers": [
    {
      "id": "sandbox-wsl.provider",
      "name": "penguin-wsl",
      "dimensions": [
        "fs-write",
        "network",
        "mask-paths",
        "closed-temp"
      ],
      "defaultFor": [
        "win32"
      ]
    }
  ],
  "PluginConfigProvider.groups": [
    {
      "id": "sandbox-wsl",
      "title": "WSL",
      "properties": {
        "exposeWindowsDrives": {
          "type": "boolean",
          "title": "Show Windows drives read-only",
          "titleZh": "以只读方式显示 Windows 磁盘",
          "description": "Off: a confined command sees only its Workspace under /mnt. On: every Windows drive is visible read-only, your profile included.",
          "descriptionZh": "关闭:被隔离的命令在 /mnt 下只能看到自己的工作区。打开:所有 Windows 磁盘以只读方式可见,包括你的用户目录。",
          "default": false
        },
        "base": {
          "type": "enum",
          "title": "Base Linux",
          "titleZh": "基础 Linux",
          "description": "What the sandbox distro is built from. Ubuntu is the ordinary Linux most tools, wheels and prebuilt binaries expect. Alpine downloads about a tenth as much, but it is musl: some native npm modules, pip wheels and downloaded binaries do not run on it.",
          "descriptionZh": "沙盒发行版基于哪个 Linux。Ubuntu 是绝大多数工具、wheel 与预编译二进制所预期的常规 Linux;Alpine 的下载量只有前者的十分之一左右,但它用 musl:部分原生 npm 模块、pip wheel 与预编译二进制无法运行。",
          "options": [
            {
              "value": "ubuntu",
              "title": "Ubuntu 24.04 LTS (about 30 MB)",
              "titleZh": "Ubuntu 24.04 LTS(约 30 MB)"
            },
            {
              "value": "alpine",
              "title": "Alpine (about 4 MB, musl)",
              "titleZh": "Alpine(约 4 MB,musl)"
            }
          ],
          "default": "ubuntu"
        },
        "packages": {
          "type": "list",
          "title": "Packages",
          "titleZh": "软件包",
          "description": "Packages Initialize installs besides bubblewrap, one per line (for example nodejs, npm, python3). They are apt packages on Ubuntu and apk packages on Alpine. Windows toolchains cannot run inside the sandbox.",
          "descriptionZh": "初始化时除 bubblewrap 外安装的软件包,每行一个(例如 nodejs、npm、python3)。Ubuntu 上是 apt 包,Alpine 上是 apk 包。Windows 工具链无法在沙盒内运行。",
          "default": [
            "git",
            "curl",
            "nodejs"
          ],
          "pattern": "^[a-z0-9][a-z0-9._+-]*$",
          "patternErrorMessage": "must be package names"
        },
        "mirror": {
          "type": "string",
          "title": "Package mirror",
          "titleZh": "软件包镜像",
          "description": "Where the packages come from, empty for the official archive: an Ubuntu mirror such as https://mirrors.tuna.tsinghua.edu.cn/ubuntu, or an Alpine one such as https://mirrors.tuna.tsinghua.edu.cn/alpine. The base rootfs itself always comes from the distribution's own site.",
          "descriptionZh": "软件包的下载地址,留空即用官方源:Ubuntu 镜像如 https://mirrors.tuna.tsinghua.edu.cn/ubuntu,Alpine 镜像如 https://mirrors.tuna.tsinghua.edu.cn/alpine。基础 rootfs 始终从发行版官方站点下载。",
          "placeholder": "https://mirrors.tuna.tsinghua.edu.cn/ubuntu",
          "pattern": "^https?://\\S+$",
          "patternErrorMessage": "must be an http(s) URL"
        },
        "distro": {
          "type": "string",
          "title": "Distro name",
          "titleZh": "发行版名称",
          "description": "The WSL distro this backend creates and runs commands in.",
          "descriptionZh": "本后端创建并在其中执行命令的 WSL 发行版。",
          "default": "penguin-sandbox",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*$",
          "patternErrorMessage": "may use letters, digits, dot, dash and underscore"
        }
      }
    }
  ]
}

Target slots: PluginLibraryModule.cards · SandboxModule.providers · PluginConfigProvider.groups

Methods (1)

setup

setup()