---
title: "Kimi Code CLI integration"
description: "Run Moonshot AI's Kimi Code CLI in an E2B sandbox from the prebuilt kimi template, headless from code or interactively from the CLI."
url: "https://e2b.dev/integrations/kimi-code-cli"
---

# Kimi Code CLI

> Run Moonshot AI's Kimi Code CLI in an E2B sandbox with a real filesystem, terminal and git. In headless mode its tool calls run without approval, inside the sandbox.

Coding agents · [All integrations](https://e2b.dev/integrations.md)

## About this integration

- **Maintained by:** E2B
- **How it works:** Prebuilt kimi template
- **Template:** kimi
- **Language:** TypeScript, Python
- **Upstream:** [MoonshotAI/kimi-code · ★ 8.3k](https://github.com/MoonshotAI/kimi-code)
- **Docs:** [docs.e2b.dev/agents/kimi-cli](https://docs.e2b.dev/agents/kimi-cli)

## Get started

Paste the prompt into your coding agent, or follow the steps yourself.

### Paste this into your coding agent

```text
Run Kimi Code CLI in an E2B sandbox from this project.

1. Install the e2b package using the project's package manager.
2. The SDK needs the E2B_API_KEY environment variable. If it isn't set, ask me for my API key from https://console.e2b.dev/?tab=keys. Never hardcode it. Kimi also needs a Moonshot AI API key, passed to the sandbox as KIMI_MODEL_API_KEY.
3. Follow the Kimi Code CLI guide at https://docs.e2b.dev/agents/kimi-cli: create a sandbox from the kimi template with KIMI_MODEL_NAME and KIMI_MODEL_API_KEY, and run kimi -p with a task.
4. Run it once, show me the output that came from the sandbox, then kill the sandbox.
```

## Or set it up yourself

### 1. Install the E2B SDK

```bash
pip install e2b
```

### 2. Set your API keys

```bash
export E2B_API_KEY="e2b_..."
export MOONSHOT_API_KEY="..."
```

### 3. Run Kimi headless

```python
import os
from e2b import Sandbox

sandbox = Sandbox.create("kimi", envs={
    "KIMI_MODEL_NAME": "kimi-k3",
    "KIMI_MODEL_API_KEY": os.environ["MOONSHOT_API_KEY"],
})

result = sandbox.commands.run(
    'kimi -p "Create a hello world HTTP server in Go"',
    timeout=0,
)

print(result.stdout)
sandbox.kill()
```

### 4. Or open it interactively

```bash
e2b sbx create kimi
kimi
```

## What runs in the sandbox

Kimi's tool calls run in the sandbox, away from your host files and credentials.

- **Code:** Shell commands, file edits and git operations. With -p, Kimi runs tool calls without asking for approval.
- **State:** Sessions are stored under ~/.kimi-code/sessions in the sandbox. kimi -r <id> continues one.
- **Secrets:** The model key goes in as KIMI_MODEL_API_KEY. Kimi doesn't read KIMI_API_KEY from the environment.
- **Network:** Sandboxes reach the internet by default. Limit where the agent connects with outbound network rules.

## More coding agents

Other coding agents that run in E2B sandboxes.

- [Gemini CLI](https://e2b.dev/integrations/gemini-cli.md): Run Google's Gemini CLI in a sandbox with full filesystem, terminal, and git access.
- [GitHub Copilot CLI](https://e2b.dev/integrations/copilot-cli.md): Run GitHub Copilot CLI in a sandbox with full filesystem, terminal, and git access.
- [Claude Code](https://e2b.dev/integrations/claude-code.md): Run Claude Code in its own sandbox with a real filesystem, terminal, and git, so it can work unattended.

## Links

- [Get API key](https://console.e2b.dev/?tab=keys)
- [Read the docs](https://docs.e2b.dev/agents/kimi-cli)
- [E2B documentation](https://docs.e2b.dev)
