Home Explore Blog CI



docker

content/reference/api/extensions-sdk/ExtensionHost.md
d11120281cd5a4afe13cd84dae691f51e9ad35b1b1833d2300000003000005ed
---
title: "Interface: ExtensionHost"
description: Docker extension API reference
keywords: Docker, extensions, sdk, API, reference
aliases:
 - /desktop/extensions-sdk/dev/api/reference/interfaces/ExtensionHost/
 - /extensions/extensions-sdk/dev/api/reference/interfaces/ExtensionHost/
---

**`Since`**

0.2.0

## Properties

### cli

• `Readonly` **cli**: [`ExtensionCli`](ExtensionCli.md)

Executes a command in the host.

For example, execute the shipped binary `kubectl -h` command in the host:

```typescript
await ddClient.extension.host.cli.exec("kubectl", ["-h"]);
```

---

Streams the output of the command executed in the backend container or in the host.

Provided the `kubectl` binary is shipped as part of your extension, you can spawn the `kubectl -h` command in the host:

```typescript
await ddClient.extension.host.cli.exec("kubectl", ["-h"], {
           stream: {
             onOutput(data): void {
                 // As we can receive both `stdout` and `stderr`, we wrap them in a JSON object
                 JSON.stringify(
                   {
                     stdout: data.stdout,
                     stderr: data.stderr,
                   },
                   null,
                   "  "
                 );
             },
             onError(error: any): void {
               console.error(error);
             },
             onClose(exitCode: number): void {
               console.log("onClose with exit code " + exitCode);
             },
           },
         });
```

Chunks
8acd1477 (1st chunk of `content/reference/api/extensions-sdk/ExtensionHost.md`)
Title: ExtensionHost Interface: cli Property
Summary
The `ExtensionHost` interface includes a `cli` property of type `ExtensionCli`, which allows extensions to execute commands in the host environment. It provides methods for executing commands and streaming their output, including `stdout`, `stderr`, error messages, and exit codes. The examples demonstrate how to use the `cli.exec` method to execute `kubectl -h` and stream its output.