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

# Context Manager

> Automatically create and delete sandboxes using Python's with statement.

The context manager is the recommended way to use the SDK. It automatically creates the sandbox on entry and deletes it on exit — even if an error occurs.

```python theme={null}
from jhansi import Sandbox

with Sandbox(language="python") as sb:
    sb.upload_file("main.py")
    result = sb.exec("python main.py")
    print(result)
```

This is equivalent to:

```python theme={null}
sb = Sandbox(language="python")
sb.create()
try:
    sb.upload_file("main.py")
    result = sb.exec("python main.py")
    print(result)
finally:
    sb.delete()
```
