---
title: use of eval can be insecure
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > use of eval can be insecure
---

# use of eval can be insecure

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site). ().
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**ID:** `python-security/no-eval`

**Language:** Python

**Severity:** Notice

**Category:** Security

**CWE**: [94](https://cwe.mitre.org/data/definitions/94.html)

**Related CWEs**:

- [96](https://cwe.mitre.org/data/definitions/96.html)
- [1336](https://cwe.mitre.org/data/definitions/1336.html)

## Description{% #description %}

`eval()` is insecure, and passing in unsanitized data could create a vulnerability, as reported by the [official Python documentation](https://docs.python.org/3/library/functions.html#eval). Generated code should be controlled as mentioned by CWE-94.

#### Learn More{% #learn-more %}

- [CWE-94](https://cwe.mitre.org/data/definitions/94.html) - Improper Control of Generation of Code

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```python
print("bla")
eval('[1, 2, 3]') # eval() can be unsafe
```

## Compliant Code Examples{% #compliant-code-examples %}

```python
import foo
foo.eval('[1, 2, 3]')
```

```python
from ast import literal_eval
print("bla")
literal_eval('[1, 2, 3]')
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}
 