Interface concepts

Interfaces are a mechanism for communication and resource sharing. It is an integral part of workshop confinement, ensuring that each workshop operates in its own isolated environment, while still allowing controlled interactions among the SDKs and with the host.

In Workshop, SDKs can act as providers and consumers of resources such as the GPU, or file directories. Host system resources are exposed via the system SDK that is present in every workshop by design.

For a workshop to be operational, the SDKs listed in its definition must connect to the resources they expect. Such connections are uniformly established via the interface system.

To achieve this, Workshop implements a counterpart to snapd’s interface manager, which controls whether an SDK can use resources beyond its confines. You can think of specific interfaces as resource types: filesystem, hardware, computing, and so on.

Specific interfaces are predefined and implemented by Workshop, so you cannot create a custom interface type. Currently, Workshop and SDKcraft support the following:

Plugs and slots

To make use of these interfaces, SDKs and workshops define slots. For example, a mount interface slot creates a source directory to be mounted inside the workshop via a plug.

Further, SDKs and workshops define plugs to connect to a slot of a certain interface type. For example, a mount interface plug mounts the slot to a target directory inside the workshop.

You can think of the plug as the recipient of the resources exposed by the slot; note that a slot can handle connections with multiple plugs.

Connections can be established:

  • Automatically: By running workshop launch, workshop refresh, or workshop start.

  • Manually: By running workshop connect after the workshop has started, or by listing connections in the workshop definition and running workshop refresh.

All connections are subject to validation. Also, automatic connections require plugs and slots to have matching details and aren’t allowed for some interfaces, such as ssh-agent. Finally, the order of automatic connections is not guaranteed, so you should not rely on it.

Validation

All plugs and slots defined for a workshop directly or via its SDKs are checked to make sure they can be installed as part of the workshop and then connected. For this, Workshop uses a set of internal rules.

Each interface has its own rule set; for example, the mount interface plug can be installed and auto-connected based on its rules alone. However, other interfaces may have different rules, such as allowing installation but not auto-connection for ssh-agent.

Connections

From the user perspective, connections can be established through the interface system in several ways:

  • The connections section of the workshop definition and the workshop connect command can be used to link interface plugs to respective slots, allowing the SDKs to orderly access the resources.

  • Conversely, the workshop disconnect command terminates existing interface connections, revoking the access to the resources granted by the connection.

  • Finally, the workshop connections command lists all existing connections and their states, providing an overview of how workshop connections are laid out.

Some plugs can be auto-connected to their slots at launch or refresh. This behavior varies by interface, but the overall aim is to conduct reasonably in each case: the mount and the GPU interfaces are auto-connected, whereas the camera, desktop, and SSH interfaces require manual connection.

To know how each kind of connection is treated when a workshop is launched, refreshed, or restored, see Connections across refresh and restore.

Plug bindings

SDKs usually access host resources via interface plugs. When multiple SDKs try to use the same resource in conflicting ways, the workshop won’t launch and shows an error.

To fix this issue, you can bind one plug to another of the same interface type. This makes both plugs point to the same resource without conflicts. Any action performed on one plug (like mounting or remounting) thus automatically applies to all bound plugs.

When you run workshop connections, a bound plug will have bind listed under Notes, along with the line number of the target plug:

$ workshop connections digits

  INTERFACE  PLUG                    SLOT                 NOTES
  mount      digits/torchaudio:hub   digits/system:mount  bind.1
  mount      digits/torchvision:hub  digits/system:mount  bind.1

Here, both plugs are listed as bind.1, pointing to torchaudio:hub in the first line.

See also

Explanation:

How-to guides:

Reference: