> ## 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.

# Sandbox Protocol • Rust AI Agent SDK

> SandboxProtocol: Protocol for sandbox implementations. Sandboxes provide isolated environments for safe code execution. Implementations can use Docker, subprocess...

# SandboxProtocol

> Defined in the [**sandbox**](../modules/sandbox) module.

<Badge color="orange">Rust AI Agent SDK</Badge>

Protocol for sandbox implementations. Sandboxes provide isolated environments for safe code execution. Implementations can use Docker, subprocess isolation, or other containerization technologies.

## Methods

### `is_available`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn is_available(&self) -> bool
```

Whether the sandbox backend is available.

### `sandbox_type`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn sandbox_type(&self) -> &str
```

Type of sandbox (docker, subprocess, etc.).

### `start`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
async fn start(&mut self) -> Result<()>
```

Start/initialize the sandbox environment.

### `stop`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
async fn stop(&mut self) -> Result<()>
```

Stop/cleanup the sandbox environment.

### `execute`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
async fn execute(
        &self,
        code: &str,
        language: &str,
        limits: Option<ResourceLimits>,
        env: Option<HashMap<String, String>>,
        working_dir: Option<String>,
    ) -> Result<SandboxResult>
```

Execute code in the sandbox.

**Parameters:**

| Name          | Type                           |
| ------------- | ------------------------------ |
| `code`        | `&str`                         |
| `language`    | `&str`                         |
| `limits`      | `Option&lt;ResourceLimits&gt;` |
| `env`         | `Option&lt;HashMap&lt;String`  |
| `working_dir` | `Option&lt;String&gt;`         |

### `execute_file`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
async fn execute_file(
        &self,
        file_path: &str,
        args: Option<Vec<String>>,
        limits: Option<ResourceLimits>,
        env: Option<HashMap<String, String>>,
    ) -> Result<SandboxResult>
```

Execute a file in the sandbox.

**Parameters:**

| Name        | Type                              |
| ----------- | --------------------------------- |
| `file_path` | `&str`                            |
| `args`      | `Option&lt;Vec&lt;String&gt;&gt;` |
| `limits`    | `Option&lt;ResourceLimits&gt;`    |
| `env`       | `Option&lt;HashMap&lt;String`     |

### `run_command`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
async fn run_command(
        &self,
        command: &str,
        limits: Option<ResourceLimits>,
        env: Option<HashMap<String, String>>,
        working_dir: Option<String>,
    ) -> Result<SandboxResult>
```

Run a shell command in the sandbox.

**Parameters:**

| Name          | Type                           |
| ------------- | ------------------------------ |
| `command`     | `&str`                         |
| `limits`      | `Option&lt;ResourceLimits&gt;` |
| `env`         | `Option&lt;HashMap&lt;String`  |
| `working_dir` | `Option&lt;String&gt;`         |

### `write_file`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
async fn write_file(&self, path: &str, content: &[u8]) -> Result<bool>
```

Write a file to the sandbox.

**Parameters:**

| Name      | Type    |
| --------- | ------- |
| `path`    | `&str`  |
| `content` | `&[u8]` |

### `read_file`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
async fn read_file(&self, path: &str) -> Result<Option<Vec<u8>>>
```

Read a file from the sandbox.

**Parameters:**

| Name   | Type   |
| ------ | ------ |
| `path` | `&str` |

### `list_files`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
async fn list_files(&self, path: &str) -> Result<Vec<String>>
```

List files in a sandbox directory.

**Parameters:**

| Name   | Type   |
| ------ | ------ |
| `path` | `&str` |

### `get_status`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn get_status(&self) -> SandboxStatusInfo
```

Get sandbox status information.

### `cleanup`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
async fn cleanup(&mut self) -> Result<()>
```

Clean up sandbox resources.

### `reset`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
async fn reset(&mut self) -> Result<()>
```

Reset sandbox to initial state.

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-rust/praisonai/src/sandbox/mod.rs">
  `praisonai/src/sandbox/mod.rs` at line 0
</Card>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Rust Database" icon="database" href="/docs/rust/database" />

  <Card title="Rust Sandbox" icon="box" href="/docs/rust/sandbox" />

  <Card title="Rust Code Execution" icon="terminal" href="/docs/rust/code-execution" />
</CardGroup>
