Skip to content

Plugin SDK: per-machine environment control for machine providers (sandbox credential isolation) #4405

Description

@jransom87

The workflow

I am building a machine-provider plugin that creates bb machines inside local microVM sandboxes (Docker Sandboxes, sbx), modeled on the builtin Modal Sandbox plugin and the community Cloud Machines (Vercel Sandbox) plugin. These sandbox products inject credentials through a host-side egress proxy: the VM only ever sees a placeholder (for example a GH_TOKEN that looks real but is not), and the proxy swaps in the real value on allowed requests. The point is that a compromised agent inside the VM cannot copy a usable token.

To keep that property, every process bb runs on the sandbox machine needs the placeholder, not the real value.

What happens today

resolveHostEnvironment sends every non-primary host the server's real gh credentials whenever the global machineGitCredentialsEnabled is on, plus global/project machine-env rows (host-environment.ts#L13-L41). That result is used for environment setup/teardown hooks, core git operations (project source clone/fetch) and terminals.

A plugin can override it only for agent commands: bb.providers.experimental_contributeEnv receives hostId, and its entries shadow the built-in and user rows for start/resume/turn (plugin-agent-contributions.ts#L72). That works; our resolver returns placeholders only for the plugin's own hosts, and we verified by hash that agent turns in the VM get the placeholder.

But there is no per-machine control for the other purposes:

  • a machine provider cannot opt its machines out of git credential forwarding (the only switch is global and would also cut off laptops and servers that need it);
  • machine-env rows are global or per project, never per host;
  • experimental_contributeEnv does not apply to hooks, core git or terminals, and cannot unset a variable.

So the real server GitHub token still reaches .bb-env-setup.sh, core git processes, terminals, and the daemon's memory inside the sandbox.

What you would expect

A machine provider can shape the host environment core sends to machines it created. One possible shape:

PluginMachineProviderDefinition.environment?: {
  forwardGitCredentials?: boolean; // default true
  contribute?(ctx: {
    hostId: string;
    projectId: string | null;
    purpose: "agent" | "hook" | "git" | "terminal";
  }): ExperimentalPluginProviderEnvEntry[] | Promise<ExperimentalPluginProviderEnvEntry[]>; // value: null = unset
}

applied inside resolveHostEnvironment for hosts owned by that provider. An alternative that also covers manually enrolled machines: per-host rows in Settings → Environment variables (bb machine env set NAME --machine <id>), including an explicit "unset/do not forward" row.

Context and alternatives

  • Affects any sandbox-style machine provider (Modal, Vercel Sandbox, Docker Sandboxes, E2B-like) that brokers credentials through a proxy.
  • Workaround today: experimental_contributeEnv for agent turns plus writing placeholders into the VM's shell profile; the real token remains in hooks, core git and terminals. Turning machineGitCredentialsEnabled off globally breaks other machines. A low-scope custom global GH_TOKEN row would apply to every machine, not just sandboxes.
  • Related but different: Plugin SDK: provider pool lanes as data, and a refuse-capable env contribution contract #3954 asks for a refuse-capable env contribution contract for account pooling; this asks for per-machine scope and coverage beyond agent commands.
  • Checked against bb 0.43.4 (desktop app) and main at a19b3ed4f7f834a1ecaa474161d031de219f5005, plugin SDK 0.5.9.

Checks

  • I searched open and closed issues for the same request.
  • If an agent wrote this, the body ends with > AGENT GENERATED.

AGENT GENERATED

Activity

  1. added
    plugins
    security
    on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pluginssecurity

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions