@penguinharness/sandbox-bwrap · plugins/sandbox-bwrap/src/index.ts:234

SandboxBwrap

component

The plugin's one module: a provider on the sandbox slot, the code half of the contribution the decorator declares (its manifest is generated into ifaces.json from here). Created per App, so a hot swap gets a fresh provider.

API

@Component({
  contributes: {
    // How the Plugins page shows this backend (read from ifaces.json, never by booting it).
    "PluginLibraryModule.cards": [
      {
        id: "sandbox-bwrap.card",
        title: "Linux Sandbox",
        titleZh: "Linux 沙箱",
        descriptionZh:
          "PenguinHarness 的 Bubblewrap 沙箱后端:在 Linux 上限制文件写入,并提供网络隔离与路径屏蔽。",
        shortDescription: "Linux: confine file writes, cut the network, mask paths.",
        shortDescriptionZh: "Linux:限制文件写入、断开网络、屏蔽路径。",
        category: "sandbox",
        icon: "icon.svg",
        preinstall: false,
      },
    ],
    "SandboxModule.providers": [
      {
        id: "sandbox-bwrap.provider",
        name: "penguin-bwrap",
        dimensions: ["fs-write", "network", "mask-paths", "closed-temp"],
        // A default backend on Linux, beside sandbox-dsh: where both load, this one serves
        // every policy, since it implements more.
        defaultFor: ["linux"],
      },
    ],
    "PluginConfigProvider.groups": [
      {
        id: "sandbox-bwrap",
        title: "Bubblewrap",
        properties: {
          runner: {
            type: "string",
            title: "bwrap program",
            titleZh: "bwrap 程序",
            description:
              "A path or a command on PATH; empty uses the bubblewrap this plugin ships, falling back to one on PATH where it carries none for this host.",
            descriptionZh:
              "路径或 PATH 上的命令名;留空则使用本插件自带的 bubblewrap,若没有适配本机的自带版本,再回退到 PATH 上的。",
            placeholder: "bwrap",
          },
          probeTimeoutSeconds: {
            type: "number",
            title: "Probe timeout (seconds)",
            titleZh: "探测超时(秒)",
            description:
              "How long the first check that bwrap works may take before it counts as unusable (1–30).",
            descriptionZh: "首次检查 bwrap 是否可用时最多等待多久(1–30),超时即视为不可用。",
            default: 5,
            // The confine-time probe blocks the server while it runs; a hanging runner must
            // not stall it for longer than this.
            minimum: 1,
            maximum: 30,
          },
        },
      },
    ],
  },
})
export class SandboxBwrap {
  @Use() private readonly config!: BwrapConfigReader;
  @Bind("sandbox-bwrap.provider") provider!: SandboxProviderSource;
  setup();
}

Dependencies & Wiring

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

Contributes

{
  "PluginLibraryModule.cards": [
    {
      "id": "sandbox-bwrap.card",
      "title": "Linux Sandbox",
      "titleZh": "Linux 沙箱",
      "descriptionZh": "PenguinHarness 的 Bubblewrap 沙箱后端:在 Linux 上限制文件写入,并提供网络隔离与路径屏蔽。",
      "shortDescription": "Linux: confine file writes, cut the network, mask paths.",
      "shortDescriptionZh": "Linux:限制文件写入、断开网络、屏蔽路径。",
      "category": "sandbox",
      "icon": "icon.svg",
      "preinstall": false
    }
  ],
  "SandboxModule.providers": [
    {
      "id": "sandbox-bwrap.provider",
      "name": "penguin-bwrap",
      "dimensions": [
        "fs-write",
        "network",
        "mask-paths",
        "closed-temp"
      ],
      "defaultFor": [
        "linux"
      ]
    }
  ],
  "PluginConfigProvider.groups": [
    {
      "id": "sandbox-bwrap",
      "title": "Bubblewrap",
      "properties": {
        "runner": {
          "type": "string",
          "title": "bwrap program",
          "titleZh": "bwrap 程序",
          "description": "A path or a command on PATH; empty uses the bubblewrap this plugin ships, falling back to one on PATH where it carries none for this host.",
          "descriptionZh": "路径或 PATH 上的命令名;留空则使用本插件自带的 bubblewrap,若没有适配本机的自带版本,再回退到 PATH 上的。",
          "placeholder": "bwrap"
        },
        "probeTimeoutSeconds": {
          "type": "number",
          "title": "Probe timeout (seconds)",
          "titleZh": "探测超时(秒)",
          "description": "How long the first check that bwrap works may take before it counts as unusable (1–30).",
          "descriptionZh": "首次检查 bwrap 是否可用时最多等待多久(1–30),超时即视为不可用。",
          "default": 5,
          "minimum": 1,
          "maximum": 30
        }
      }
    }
  ]
}

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

Methods (1)

setup

setup()