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

# Validate Within Dir • AI Agent SDK

> validate_within_dir: Validate that a path is contained within an allowed root directory.

# validate\_within\_dir

<div className="flex items-center gap-2">
  <Badge color="teal">Function</Badge>
</div>

> This function is defined in the [**workspace**](../modules/workspace) module.

Validate that a path is contained within an allowed root directory.

## Signature

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def validate_within_dir(path: Path, allowed_root: Path) -> bool
```

## Parameters

<ParamField query="path" type="Path" required={true}>
  Path to validate
</ParamField>

<ParamField query="allowed_root" type="Path" required={true}>
  Root directory that must contain the path
</ParamField>

### Returns

<ResponseField name="Returns" type="bool">
  True if path is within allowed\_root, False otherwise
</ResponseField>

## Uses

* `relative_to`
* `path.resolve`
* `allowed_root.resolve`

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/workspace/__init__.py#L153">
  `praisonaiagents/workspace/__init__.py` at line 153
</Card>
