Skip to main content

Sandbox backends

What the engine expects from a sandbox backend, and how a backend proves it.

Every command an agent runs goes through the SandboxProvider port. Three backends exist today: Docker, Kubernetes and the optional OpenShell plugin (sandboxes/openshell, pinned to OpenShell 0.1.8). Another one can be added as a plugin. Requirements: FR41 and FR13.

The contract​

The engine relies on promises that no backend can break. afe_core.contract.SandboxContract writes them as tests, beside StoreContract and BrokerContract. A backend passes the contract or it is not a backend.

The contract proves that:

  • open twice with the same key, scope and specification returns the same sandbox.
  • A changed specification recreates the sandbox on the same volume. A file written before is still there.
  • exec returns the exit code and the merged output. A command past its timeout is killed and reports timed_out.
  • run passes an argument list untouched, and passes binary standard input through.
  • put then get round-trips binary bytes, from 0 bytes to 50 MB.
  • stream carries line-delimited JSON both ways. close ends the process, also after it exited.
  • A sandbox removed behind the engine's back raises SandboxGone from exec, run, put and get.
  • remove_ticket removes everything of the ticket, returns the names, and does nothing the second time.
  • Two tickets never share a sandbox or a volume.
  • An environment name reaches the process with its value. The value appears in no argument list the backend runs, and in no name, label or annotation of an object it creates.

The Docker backend can pass the value only through the container's own config, which docker inspect shows. The contract allows this: Docker's contract test compares the created objects without the environment there, and says why.

Capabilities​

Some promises depend on the environment, not on the code. The contract has three capability flags, all off by default:

  • network isolation: With no egress, no host is reachable.
  • egress allowlist: With egress, only the listed hosts are reachable, also from a program that ignores the proxy variables.
  • host folder: A host folder mounts at /workspace.

A backend switches a flag on when its environment can run the cases. A case with its flag off is skipped, and the skip names the flag.

The host-folder flag is also a plugin capability. A plugin lists hostFolder in the capabilities of its sandboxes port. afe validate refuses a folder project whose runtime's sandbox plugin lacks it, and the message names the plugin. Docker declares hostFolder. Kubernetes does not.

Where the contract runs​

  • The local provider runs it in make test, with every capability off.
  • Docker runs it in make integration, with all three capabilities on.
  • Kubernetes runs it on kind in make kind-test, with network isolation and egress allowlist on.

Common security rules​

Every backend keeps the same rules, whatever it runs on:

  • A secret is named, never passed. An environment value appears in no argument list and in no name, label or annotation of a created object. Docker keeps it in the container's own config, the only way it can pass it.
  • Forge tokens and engine keys never enter a sandbox.
  • A project with no egress gets no network.
  • A project with egress reaches only the listed hosts. The field stays a list of hosts.

Backend settings​

A backend takes its own settings in Runtime.spec.sandbox.options. afe validate checks the map against the config_schema of the plugin that type selects. An unknown key or a wrong type is an error with its path. Values are settings, never secrets: a secret is named by an environment variable the plugin reads. See the Runtime reference.

A paused ticket​

A backend that can suspend releases the compute of a paused ticket and keeps its volume. On Kubernetes the ticket's Pod is deleted and its volume stays. See Kubernetes. Docker and the fakes keep the sandbox running.

See also​