> ## 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.

# Kill a sandbox

> Shut down a sandbox permanently from a connected handle, by sandbox ID, or in bulk from the CLI, alone or filtered by state and metadata.

Killing a sandbox shuts it down and permanently removes it. A killed sandbox cannot be resumed or reconnected. Kill sandboxes from the SDK or from the CLI.

> [!NOTE]
>
> Install the SDK, or the CLI for `ppio` commands, and set the `PPIO_API_KEY` and `PPIO_DOMAIN` environment variables before running these examples. See [Quickstart](https://docs.ppio.ai/sandbox/quickstart.md) and [Install and authenticate](https://docs.ppio.ai/sandbox/cli/install.md).

> [!WARNING]
>
> Killing a sandbox is irreversible. It releases the resources of the sandbox and deletes its data.

## Kill a connected sandbox

Call `kill()` on the sandbox handle.

```python Python theme={null}
from ppio_sandbox import PPIO

ppio = PPIO()
sandbox = ppio.sandbox.create()

# ... use the sandbox ...

sandbox.kill()
```

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

const ppio = new PPIO()
const sandbox = await ppio.sandbox.create()

// ... use the sandbox ...

await sandbox.kill()
```

## Kill by sandbox ID

Use the namespace `kill` method when only the sandbox ID is at hand. It returns `true` if the sandbox was found and killed, and `false` if no sandbox with that ID exists. In the examples, `sbx-123` and `<sandbox-id>` stand for a sandbox ID.

```python Python theme={null}
from ppio_sandbox import PPIO

ppio = PPIO()
killed = ppio.sandbox.kill("sbx-123")
if not killed:
    print("Sandbox not found")
```

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

const ppio = new PPIO()
const killed = await ppio.sandbox.kill('sbx-123')
if (!killed) {
  console.log('Sandbox not found')
}
```

```bash CLI theme={null}
# Kill a sandbox by ID (alias: sandbox kl)
ppio sandbox kill <sandbox-id>
```

## Kill all sandboxes

The CLI can kill every running sandbox at once with `-a` / `--all`, optionally filtered by state or metadata.

```bash CLI theme={null}
# Kill all running sandboxes
ppio sandbox kill -a

# Filter which ones to kill by state or metadata
ppio sandbox kill -a --state running
ppio sandbox kill -a --metadata env=test
```

**-a, --all** `boolean`

Kill every running sandbox at once.

**-s, --state** `string`

Filter which ones to kill by state.

**-m, --metadata** `string`

Filter which ones to kill by metadata.


## Related topics

- [Agent Sandbox errors](https://docs.ppio.ai/sandbox/errors.md)
- [Open an interactive terminal (PTY)](https://docs.ppio.ai/sandbox/terminal.md)
- [Sandbox lifecycle and states](https://docs.ppio.ai/sandbox/lifecycle.md)


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