Skip to content

Kimi CLI Example

Run Kimi Code CLI (Moonshot AI) inside an OpenSandbox container.

Start OpenSandbox server [local]

Pre-pull the code-interpreter image (includes Python 3.12+):

shell
docker pull sandbox-registry.cn-zhangjiakou.cr.aliyuncs.com/opensandbox/code-interpreter:v1.1.0

# use docker hub
# docker pull opensandbox/code-interpreter:v1.1.0

Then start the local OpenSandbox server, stdout logs will be visible in the terminal:

shell
uv pip install opensandbox-server
opensandbox-server init-config ~/.sandbox.toml --example docker
opensandbox-server

Create and Access the Kimi Sandbox

shell
# Install OpenSandbox package
uv pip install opensandbox

# Run the example (requires SANDBOX_DOMAIN / SANDBOX_API_KEY / KIMI_API_KEY)
uv run python examples/kimi-cli/main.py

The script installs Kimi Code CLI (pip install kimi-cli) at runtime (Python 3.12+ is already in the code-interpreter image), then sends a simple request kimi -p "Compute 1+1=?.". Auth is passed via KIMI_API_KEY, and you can override endpoint/model with KIMI_BASE_URL / KIMI_MODEL_NAME.

Environment Variables

VariableDefaultDescription
SANDBOX_DOMAINlocalhost:8080Sandbox service address
SANDBOX_API_KEY(optional for local)API key if your server requires authentication
SANDBOX_IMAGEsandbox-registry.cn-zhangjiakou.cr.aliyuncs.com/opensandbox/code-interpreter:v1.1.0Sandbox image to use
KIMI_API_KEY(required)Your Moonshot AI / Kimi API key
KIMI_BASE_URL(optional)Kimi API endpoint (defaults to Kimi's official endpoint)
KIMI_MODEL_NAMEkimi-k2.5Model to use

References

Released under the Apache 2.0 License.