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

# 初めての Agent Sandbox を作成する

## アカウントを作成する

Novita アカウントをお持ちでない場合は、まず <Link href="https://novita.ai/user/register" target="_blank">サインアップ</Link> してください。詳細については、<Link href="/docs/ja/guides/quickstart">クイックスタートガイド</Link> を参照してください。

新規ユーザーは、簡単なアカウント設定アンケートを完了することで、\$100 分の無料 Sandbox クレジットを受け取れます。クレジットカードは不要です。

## API キーを作成する

Novita の <Link href="https://novita.ai/settings/key-management" target="_blank">キー管理ページ</Link> に移動し、API キーを作成して、以降の手順で使用するために API キーの値を保存します。

## SDK をインストールする

次のコマンドを実行して Novita SDK をインストールできます。

<CodeGroup isTerminalCommand>
  ```bash JavaScript & TypeScript SDK icon="terminal" theme={"system"}
  npm i novita-sandbox
  ```

  ```bash Python SDK icon="terminal" theme={"system"}
  pip install novita-sandbox
  ```
</CodeGroup>

## 環境変数を設定する

プロジェクトフォルダーに `.env` ファイルが存在しない場合は作成し、API キーを設定します。

<Warning>
  JavaScript および TypeScript プロジェクトでは、プロジェクト内で `dotenv/config` パッケージを import する必要があります。Python プロジェクトでは、プロジェクト内で `dotenv` ライブラリを import し、`load_dotenv` メソッドを呼び出して環境変数を読み込む必要があります。
  詳細については、[例](#use-sdk-to-start-agent-sandbox)を参照してください。
</Warning>

```bash .env icon="terminal" highlight={2} theme={"system"}
NOVITA_API_KEY=sk_*** # Novita API key obtained from previous steps
```

または、ターミナルで環境変数を設定して API キーを構成することもできます。

```bash Bash icon="terminal" highlight={2} theme={"system"}
export NOVITA_API_KEY=sk_*** # Novita API key obtained from previous steps
```

## SDK を使用して Agent Sandbox を起動する

以下は、Sandbox を作成し、その中でコードを実行し、Sandbox ファイルシステム内のファイルを一覧表示する方法を示す簡単な例です。

<CodeGroup>
  ```js JavaScript & TypeScript icon="js" theme={"system"}
  // index.ts
  import 'dotenv/config'
  import { Sandbox } from 'novita-sandbox/code-interpreter'

  // The .env file should be located in the project root directory
  // dotenv/config will automatically look for .env in the current working directory
  // Or 
  // You can set the environment variable in the command line
  // export NOVITA_API_KEY=sk_***

  async function main() {
    const sandbox = await Sandbox.create()
    try {
      const execution = await sandbox.runCode('print("hello world")')
      console.log(execution.logs)

      const files = await sandbox.files.list('/tmp')
      console.log(files)
    } finally {
      // Close sandbox when no longer needed
      await sandbox.kill()
    }
  }
  main().catch((err) => {
    console.error(err)
    process.exit(1)
  })

  ```

  ```python Python icon="python" theme={"system"}
  # main.py
  from dotenv import load_dotenv
  from novita_sandbox.code_interpreter import Sandbox


  # The .env file should be located in the project root directory
  # dotenv will automatically look for .env in the current working directory
  load_dotenv()

  # Or 
  # You can set the environment variable in the command line
  # export NOVITA_API_KEY=sk_***

  sandbox = Sandbox.create()
  execution = sandbox.run_code("print('hello world')")
  print(execution.logs)

  files = sandbox.files.list("/")
  print(files)

  # Close sandbox when no longer needed
  sandbox.kill()
  ```
</CodeGroup>

次のコマンドを実行してコードを実行します。

<CodeGroup isTerminalCommand>
  ```bash index.ts icon="terminal" theme={"system"}
  npx tsx ./index.ts
  ```

  ```bash main.py icon="terminal" theme={"system"}
  python main.py
  ```
</CodeGroup>
