---
title: Python代码的沙箱内执行
description: "宿主机命令执行路径为“/opt/e2b-infra”。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengaiagent/bestpractice/aiagent-0301.html
sourcePath: /source/zh/kunpengaiagent/bestpractice/aiagent-0301.html
indexId: 4cfc8c8323d71dc78f33486c127ec9eba4123db149a4d1ed20d2195a689b4a4456
---
# Python代码的沙箱内执行

宿主机命令执行路径为“/opt/e2b-infra”。


1. 构造Agent容器，使用名为openclaw的沙箱（即默认沙箱案例，可参考文档E2B沙箱服务部署（可选））。

```
bash build.sh --deploy-plugin openclaw openclaw app=openclaw-deployment default
```


2. 执行kubectl get pods，查看openclaw容器名。
3. 进入openclaw对应容器。

```
kubectl exec -it <pod名称> -- bash
```


4. 进入龙虾。

```
openclaw tui
```


  告诉龙虾“请给我写一个Python的Dijkstra最短路径算法的实现。代码的执行和验证使用local-exec执行。”

  对应路径下也可以看到本地保存的Python代码。
