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

# Create your first sandbox

> Create a PPIO API key, install the Agent Sandbox SDK for Python or Node.js, set two environment variables, and run your first sandbox program.

Agent Sandbox provides official SDKs for application code in Python and Node.js. This page goes from an API key to a program that creates a sandbox, runs code inside it, and lists files in the sandbox filesystem.

> [!NOTE]
>
> Requirements: Python 3.10+ or Node.js 20+.

## Set up and run the example

**1. Create an API key**

Open the **API Keys** page of the [console](https://console.ppio.ai/api-keys) and select **Add New Key**. Keep the key for the environment setup step.

**2. Install the SDK**

Install the package for the language the example runs in.

```bash Python theme={null}
pip install ppio-sandbox
```

```bash Node.js theme={null}
npm i ppio-sandbox
```

**3. Set environment variables**

Set two environment variables before running any example. Replace `<your-api-key>` with a key from the **API Keys** page of the [console](https://console.ppio.ai/api-keys).

> [tab] macOS and Linux
>
> ```bash theme={null}
> export PPIO_API_KEY="<your-api-key>"
> export PPIO_DOMAIN="sandbox.ppio.ai"
> ```

> [tab] Windows (PowerShell)
>
> ```powershell theme={null}
> $env:PPIO_API_KEY = "<your-api-key>"
> $env:PPIO_DOMAIN = "sandbox.ppio.ai"
> ```

The SDK and the CLI read both variables from the environment.

**PPIO\_API\_KEY** `string`

Authenticates requests to Agent Sandbox.

**PPIO\_DOMAIN** `string`

Selects the Agent Sandbox service for ppio.ai. Without it, the SDK and the CLI connect to their built-in default service instead.

> [!NOTE]
>
> These commands set the variables for the current terminal session only.

**4. Run the example**

The program creates a sandbox, runs one line of Python inside it, and lists the entries under `/tmp`. Save it as `main.py` or `index.mts`, then run the saved file.

```python Python theme={null}
# main.py
from ppio_sandbox import PPIO

ppio = PPIO()
sandbox = ppio.code_interpreter.create()
try:
    execution = sandbox.run_code("print('hello world')")
    print(execution.logs)

    entries = sandbox.files.list("/tmp")
    print(entries)
finally:
    sandbox.kill()
```

```javascript Node.js theme={null}
// index.mts
import { PPIO } from 'ppio-sandbox'

const ppio = new PPIO()
const sandbox = await ppio.codeInterpreter.create()
try {
  const execution = await sandbox.runCode('print("hello world")')
  console.log(execution.logs)

  const entries = await sandbox.files.list('/tmp')
  console.log(entries)
} finally {
  await sandbox.kill()
}
```

```bash Python theme={null}
python main.py
```

```bash Node.js theme={null}
npx tsx index.mts
```

**5. Clean up**

Close the sandbox when it is no longer needed. Both examples do this by calling `kill()` in a `finally` block.

> [!TIP]
>
> A finished run prints the execution logs, which contain `hello world`, followed by the entries under `/tmp`.

## Next steps

> [card] [Create a sandbox](https://docs.ppio.ai/sandbox/create.md)
>
> Choose a template and set the timeout, environment variables and metadata.

> [card] [Agent Sandbox overview](https://docs.ppio.ai/sandbox/overview.md)
>
> Learn the core concepts: sandboxes, templates and snapshots.


## Related topics

- [Create a sandbox](https://docs.ppio.ai/sandbox/create.md)
- [Build a template with the CLI](https://docs.ppio.ai/sandbox/templates/build-cli.md)
- [Agent Sandbox errors](https://docs.ppio.ai/sandbox/errors.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.