*Environments* provide a way to configure certain choices the framework makes
for components in a [realm](https://fuchsia.dev/fuchsia-src/concepts/components/v2/realms.md).
[Component manifests](https://fuchsia.dev/fuchsia-src/concepts/components/v2/component_manifests.md) may define environments and
assign them to child realms. An environment applies to a component instance's
entire realm, unless some sub-realm overrides it (see
[Propagation](https://fuchsia.dev/fuchsia-src/concepts/components/v2/environments#propagation)).

## Properties

Environments let you configure the following behavior of a realm:

- [Component runners](https://fuchsia.dev/fuchsia-src/concepts/components/v2/environments#runners)
- [Component resolvers](https://fuchsia.dev/fuchsia-src/concepts/components/v2/environments#resolvers)

### Runners

The component framework is runtime-agnostic and can support new runtime
environments and programming languages without requiring changes to
component manager or to other components. Runners provide the extension point
for components to interact with component manager and add runtime support to
Fuchsia. Some example runners are:

- The [ELF runner](https://fuchsia.dev/docs/concepts/components/v2/elf_runner) runs binaries compiled to the ELF file format.
- The Dart AOT runner provides a runtime for Dart programs, such as a VM.
- The Chromium web runner provides a runtime for components implemented as web pages.

Component manager identifies *what* to execute and delegates *how* execution
works to the runner. Runner implementations are free to choose an appropriate
strategy for executing their components, including:

- Start a new process for the component.
- Isolate the component within a virtual machine.
- Run the component in the same process as the runner.
- Execute the component as a job on a remote computer.

For more details on using and implementing runners, see
[runner capabilities](https://fuchsia.dev/fuchsia-src/concepts/components/v2/capabilities/runner).

### Resolvers

Component resolvers interact with component manager on behalf of a component to
resolve its children from a given


[](https://fuchsia.dev/docs/glossary#component-url)


.
Resolvers are registered with a particular URL scheme (`http`, `fuchsia-pkg`, etc.)
and provide an implementation to fetch the component from the desired URL and
return a


[](https://fuchsia.dev/docs/glossary#component-declaration)


.

If the component being resolved has an associated package, the resolver also
returns a [`fuchsia.io.Directory`](https://cs.opensource.google/fuchsia/fuchsia/+/main:/sdk/fidl/fuchsia.io/directory.fidl) handle representing the
package directory.

For more details on using and implementing resolvers, see
[resolver capabilities](https://fuchsia.dev/fuchsia-src/concepts/components/v2/capabilities/resolver).

## Declaring

Define a new environment by adding an [environments](https://fuchsia.dev/reference/cml#environments)
declaration to a [component manifest](https://fuchsia.dev/fuchsia-src/concepts/components/v2/component_manifests.md).

For an environment to be used, you must assign it to a child or collection. See
[Propagation](https://fuchsia.dev/fuchsia-src/concepts/components/v2/environments#propagation).

Environments support two modes of extension, [`REALM`](https://cs.opensource.google/fuchsia/fuchsia/+/main:/sdk/fidl/fuchsia.component.decl/environment.fidl) or
[`NONE`](https://cs.opensource.google/fuchsia/fuchsia/+/main:/sdk/fidl/fuchsia.component.decl/environment.fidl):

- [`REALM`](https://cs.opensource.google/fuchsia/fuchsia/+/main:/sdk/fidl/fuchsia.component.decl/environment.fidl): The environment inherits its properties from the environment that was assigned to this component (the "parent environment"). Any new properties will be added on top of those inherited from the parent environment. Any properties that overlap with the parent environment will override the parent.
- [`NONE`](https://cs.opensource.google/fuchsia/fuchsia/+/main:/sdk/fidl/fuchsia.component.decl/environment.fidl): The environment starts empty, with no initial properties.

## Propagation

A component instance is assigned an environment in one of two ways:

- Its [child](https://fuchsia.dev/reference/cml#children) or [collection](https://fuchsia.dev/reference/cml#collections) does not have `environment` set. In this case, it will receive its parent's environment. This is the most common case.
- Its [child](https://fuchsia.dev/reference/cml#children) or [collection](https://fuchsia.dev/reference/cml#collections) sets `environment`, which refers to one of the [`environments`](https://fuchsia.dev/reference/cml#environments) defined by this component.

The [root component](https://fuchsia.dev/fuchsia-src/concepts/components/v2/component_manager.md#booting-the-system) is assigned an environment by
[component manager](https://fuchsia.dev/fuchsia-src/concepts/components/v2/component_manager.md). This includes a bootstrap resolver,
the [ELF runner](https://fuchsia.dev/fuchsia-src/concepts/components/v2/elf_runner.md), and default configuration options.

## Environments vs. capability routing

The semantics of environments contrast with
[capability routing](https://fuchsia.dev/fuchsia-src/concepts/components/v2/capabilities/README.md#routing). With capability routing, a
capability must be explicitly [exposed](https://fuchsia.dev/reference/cml#expose) or [offered](https://fuchsia.dev/reference/cml#offer) by
every component in the path from the provider to the consumer. The explicit
nature of capability routing makes it easy to guarantee that components don't
receive access to capabilities they shouldn't have, thus maintaining the
[principle of least privilege](https://en.wikipedia.org/wiki/Principle_of_least_privilege).

However, there are some configuration choices that don't make sense to configure
on a per-component basis. For example, consider [runners](https://fuchsia.dev/fuchsia-src/concepts/components/v2/capabilities/runner.md). Almost
every component needs to use a runner, but defining a new runner is not very
common -- certainly less common than defining a protocol capability, for
instance. Furthermore, access to a runner doesn't inherently grant a component
much privilege, for the component framework mediates access to the runner's
protocol and the component can't use that protocol directly. Therefore, runner
capabilities are registered in an environment, which makes them available to any
component in the realm to which that environment was assigned (unless some
sub-realm decides to set a new environment with the runner absent).
[](https://issues.fuchsia.dev/issues/new?component=1439230&template=1881640&description=Issue+on:+https://fuchsia.dev/docs/concepts/components/v2/environments.md "Report a bug or suggest improvements on this page") [](https://cs.opensource.google/fuchsia/fuchsia/+/main:docs/concepts/components/v2/environments.md "View the source code of this page") [](https://ci.android.com/edit?repo=fuchsia/fuchsia/main&file=docs/concepts/components/v2/environments.md&cloneRepo=fuchsia/fuchsia:refs/heads/main&fullPath=fuchsia/docs/concepts/components/v2/environments.md "Edit the source code of this page")