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

# Exécuter des commandes dans le sandbox

export const SandboxCliConfigHint = () => {
  if (typeof document === "undefined") {
    return null;
  } else {
    return <Note>Before running the command-line related example code in this document, please refer to the <Link href="/docs/fr/guides/sandbox-cli">tutorial</Link> to install the CLI and complete <Link href="/docs/fr/guides/sandbox-cli-auth">authentication</Link>.</Note>;
  }
};

<SandboxCliConfigHint />

Vous pouvez exécuter des commandes dans un sandbox en cours d’exécution et recevoir leur sortie à l’aide de la commande suivante.

```bash Bash icon="terminal" theme={"system"}
novita-sandbox-cli sandbox exec <sandbox-id> <command>
```

### Options d’exécution

L’option `--background` vous permet d’exécuter une commande en arrière-plan et de retourner immédiatement. La commande affichera l’identifiant du processus (PID) sur stderr :

```bash Bash icon="terminal" theme={"system"}
novita-sandbox-cli sandbox exec --background <sandbox-id> "sleep 60 && echo done"
```

L’option `--cwd` spécifie le répertoire de travail de la commande.

```bash Bash icon="terminal" theme={"system"}
novita-sandbox-cli sandbox exec --cwd /home/user <sandbox-id> ls
```

L’option `--user` spécifie l’utilisateur avec lequel exécuter la commande.

```bash Bash icon="terminal" theme={"system"}
novita-sandbox-cli sandbox exec --user root <sandbox-id> apt-get update
```

L’option `--env` vous permet de définir des variables d’environnement. Répétez l’option pour définir plusieurs variables.

```bash Bash icon="terminal" theme={"system"}
novita-sandbox-cli sandbox exec --env NODE_ENV=production --env DEBUG=true <sandbox-id> node app.js
```
