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

# サンドボックスでコマンドを実行する

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/ja/guides/sandbox-cli">tutorial</Link> to install the CLI and complete <Link href="/docs/ja/guides/sandbox-cli-auth">authentication</Link>.</Note>;
  }
};

<SandboxCliConfigHint />

次のコマンドを使用して、実行中のサンドボックスでコマンドを実行し、その出力を受け取ることができます。

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

### 実行オプション

`--background` フラグを使用すると、バックグラウンドでコマンドを実行し、すぐに戻ることができます。このコマンドはプロセス ID（PID）を stderr に出力します。

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

`--cwd` フラグは、コマンドの作業ディレクトリを指定します。

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

`--user` フラグは、コマンドを実行するユーザーを指定します。

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

`--env` フラグを使用すると、環境変数を設定できます。複数の変数を設定するには、このフラグを繰り返し指定します。

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