# Code Interpreter

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

## Introduction

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 the code with the chart
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 the chart in the results (if any)
for result in execution.results:
    if result.png:
        print(f"Generated PNG image of {len(result.png)} bytes")

sandbox.kill()
```

## Main functions

- **Stateful Execution**: Variables and state are maintained across multiple `run_code` calls.
- **Rich Media Output**: Supports text, PNG/JPEG images, and even matplotlib charts.
- **File Operation**: You can upload/download files to the sandbox environment.

