Skip to main content

Coding agents

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.

Maintained by
E2B
How it works
Prebuilt kimi template
Template
kimi
Language
TypeScript, Python

Set it up

Get started

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

Paste this into your coding agent

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

  1. 1.Install the e2b package using the project's package manager.
  2. 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. 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. 4.Run it once, show me the output that came from the sandbox, then kill the sandbox.

Or set it up yourself

  1. 1. Install the E2B SDK

    pip install e2b
  2. 2. Set your API keys

    export E2B_API_KEY="e2b_..."
    export MOONSHOT_API_KEY="..."
  3. 3. Run Kimi headless

    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. 4. Or open it interactively

    e2b sbx create kimi
    kimi

Security

What runs in the sandbox

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

  • CodeShell commands, file edits and git operations. With -⁠p, Kimi runs tool calls without asking for approval.
  • StateSessions are stored under ~/.kimi-code/sessions in the sandbox. kimi -⁠r <id> continues one.
  • SecretsThe model key goes in as KIMI_MODEL_API_KEY. Kimi doesn't read KIMI_API_KEY from the environment.
  • NetworkSandboxes reach the internet by default. Limit where the agent connects with outbound network rules.

3B+ sandboxes started

Give every agent a machine