# Code Interpreter

Code Interpreter provides a stateful Jupyter notebook environment that supports running Python code, generating charts, processing files, etc. It is very suitable for AI code execution, data analysis, and visualization tasks.

## Import

Code Interpreter is located in the `ucloud_sandbox.code_interpreter` module.

```python
from ucloud_sandbox.code_interpreter import Sandbox
```

## Quick Start

```python
from ucloud_sandbox.code_interpreter import Sandbox

# Create a Code Interpreter instance
sandbox = Sandbox.create()

# Run code
execution = sandbox.run_code("print('Hello, World!')")
print(execution.logs.stdout)  # Output: Hello, World!

# Run code with charts
code = """
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10, 100)
y = np.sin(x)

plt.plot(x, y)
plt.show()
"""
execution = sandbox.run_code(code)

# Get charts from results (if any)
for result in execution.results:
    if result.png:
        print(f"Generated PNG image of {len(result.png)} bytes")

sandbox.kill()
```

## Main Features

- **Stateful Execution**: Variables and state persist across multiple `run_code` calls.
- **Rich Media Output**: Supports text, PNG/JPEG images, and even matplotlib charts.
- **File Operations**: Can upload/download files to/from the sandbox environment.

