> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# execute • AI Agent SDK

> execute: Execute code in the sandbox.

# execute

<div className="flex items-center gap-2">
  <Badge color="blue">Async</Badge>
  <Badge color="purple">Method</Badge>
</div>

> This is a method of the [**SandboxProtocol**](../classes/SandboxProtocol) class in the [**protocols**](../modules/protocols) module.

Execute code in the sandbox.

## Signature

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
async def execute(code: str, language: str, limits: Optional[ResourceLimits], env: Optional[Dict[str, str]], working_dir: Optional[str]) -> SandboxResult
```

## Parameters

<ParamField query="code" type="str" required={true}>
  Code to execute
</ParamField>

<ParamField query="language" type="str" required={false} default="'python'">
  Programming language (python, bash, etc.)
</ParamField>

<ParamField query="limits" type="Optional" required={false}>
  Resource limits for execution
</ParamField>

<ParamField query="env" type="Optional" required={false}>
  Environment variables
</ParamField>

<ParamField query="working_dir" type="Optional" required={false}>
  Working directory for execution
</ParamField>

### Returns

<ResponseField name="Returns" type="SandboxResult">
  Execution result
</ResponseField>

## Used By

* [`CodeAgent.execute_code`](../functions/CodeAgent-execute_code)
* [`CodeAgent.aexecute`](../functions/CodeAgent-aexecute)
* [`MiddlewareManager.execute_model_call`](../functions/MiddlewareManager-execute_model_call)
* [`MiddlewareManager.execute_tool_call`](../functions/MiddlewareManager-execute_tool_call)
* [`HookRunner.execute_sync`](../functions/HookRunner-execute_sync)

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/sandbox/protocols.py#L233">
  `praisonaiagents/sandbox/protocols.py` at line 233
</Card>
