# Installing our SDK

This guide will walk you through the essential workflow of using our SDK to interact with the Codeset API. You will learn how to create a session, execute commands within it, verify the outcome, and properly close the session.

## Prerequisites

Before you begin, you will need to have the following installed:

* Python 3.7 or later
* The `codeset` library

## Step 1: Install the Codeset SDK

You can install the `codeset` library using pip (or other alternative):

```bash
pip install codeset
```

## Step 2: Create a Session

The first step is to create a session. A session represents a sandboxed environment where you can execute commands and run verifications. To create a session, you will need to provide a `dataset` and `sample_id`. A `sample_id` is a unique identifier for a specific task or problem.

```python
from codeset import Codeset
import os

client = Codeset(api_key=os.getenv("CODESET_API_KEY"))

session = client.sessions.create(
    dataset="codeset-gym-python",
    sample_id="matiasb__python-unidiff-19"
)
```

## Step 3: Interact with the Session

Once you have created a session, you can execute commands in the sandboxed environment. For example, you can run tests or explore the codebase:

```python
response = client.sessions.execute_command(
    session_id=session.session_id,
    command="pwd && ls -la"
)

print(response.stdout)
```

## Step 4: Apply Changes

If you need to modify files in the environment, you can use the `str_replace` method:

```python
client.sessions.str_replace(
    session_id=session.session_id,
    file_path="src/example.py",
    str_to_replace="old_code",
    str_to_insert="new_code"
)
```

## Step 5: Verify the Outcome

After you have executed your commands, you can verify the results. A verification is a process that checks if the task has been completed successfully.

```python
import time

# Start verification
verify_response = client.sessions.verify.start(session_id=session.session_id)

# Wait for verification to complete
while True:
    status_response = client.sessions.verify.status(
        job_id=verify_response.job_id,
        session_id=session.session_id
    )
    if status_response.status in ["completed", "error", "cancelled"]:
        break
    time.sleep(1)

# Check if verification was successful
if status_response.status == "completed" and status_response.result:
    print(f"Verification successful: {status_response.result.is_success}")
    print(f"Tests passed: {status_response.result.passed}/{status_response.result.total}")
```

## Step 6: Close the Session

Finally, you should close the session to release the resources.

```python
client.sessions.close(session_id=session.session_id)
```
