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

# CoreWeave Sandboxes を使い始める

> Forge の APIキーまたは CoreWeave API アクセストークンを使用して、サーバーレスキャパシティ上で最初のサンドボックスを実行します。

サーバーレスキャパシティ上のサンドボックスでコマンドを実行し、その出力を表示します。クラスターのセットアップは必要ありません。

<h2 id="before-you-begin">
  始める前に
</h2>

サーバーレスサンドボックスは一般提供されており、使用量に応じて課金されます。アクセスは組織単位で有効化されます。組織のアクセスをリクエストするには、[サポート](mailto:forge-support@coreweave.com)にお問い合わせください。

組織で Forge 専用クラウドを使用している場合は、[Forge 専用クラウドでサンドボックスを使用する](/ja/products/sandboxes/dedicated-cloud)の手順に従ってください。

<h2 id="run-your-first-sandbox">
  最初のサンドボックスを実行する
</h2>

<span id="choose-a-credential" />

<span id="run-a-sandbox-on-serverless-capacity" />

サンドボックスを所有し、その料金の請求先となるアカウントの認証情報を選択します。Forge APIキーはサーバーレスへの配置をサポートしています。CoreWeave API アクセストークンは、サーバーレスと CoreWeave Kubernetes Service (CKS) の両方への配置をサポートしています。アカウントの要件については、[認証情報を選択して取得する](/ja/products/sandboxes/placement#choose-and-get-credentials)を参照してください。使用する認証情報に対応するセクションの手順を実行してから、[結果を検証](#verify-the-result)してください。

<h3 id="forge-api-key">
  Forge APIキー
</h3>

[Forge APIキー](https://forge.coreweave.com/settings#apikeys)を取得します。アカウントをお持ちでない場合は、同じリンクから新規登録してください。次に、ターミナルでキーを設定します。以下の例では `FORGE_API_KEY` を明示的に読み取っています。SDK はこの環境変数を自動的には検出しません。

```bash theme={"system"}
export FORGE_API_KEY="[FORGE-API-KEY]"
```

<Tabs>
  <Tab title="Python">
    [`uv`](https://docs.astral.sh/uv/getting-started/installation/) をインストールした状態で、次の内容を `hello.py` として保存します。

    ```python title="hello.py" theme={"system"}
    import os
    from cwsandbox import AuthHeaders, Sandbox

    forge_auth = AuthHeaders(
        headers={"x-wandb-api-key": os.environ["FORGE_API_KEY"]},
        strategy="wandb_api_key",
    )

    with Sandbox.run(
        auth=forge_auth,
        resources={"cpu": "1", "memory": "1Gi"},
    ) as sandbox:
        print(sandbox.exec(["echo", "Hello!"]).result().stdout)
    ```

    Python 3.11 とサンドボックスクライアントを使用して実行します。これらがインストールされていない場合は、次のコマンドによって自動的にインストールされます。

    ```bash theme={"system"}
    uv run --python 3.11 --with 'cwsandbox>=1.14.2' hello.py
    ```
  </Tab>

  <Tab title="TypeScript">
    Node.js 22 以降をインストールした状態で、クライアントをインストールします。

    ```bash theme={"system"}
    npm install @coreweave/cwsandbox
    ```

    次の内容を `hello.mts` として保存します。

    ```typescript title="hello.mts" theme={"system"}
    import { createSandboxClient } from "@coreweave/cwsandbox/wandb";

    const client = createSandboxClient({
      apiKey: process.env.FORGE_API_KEY,
    });
    const result = await client.withSandbox(
      async (sandbox) => sandbox.commands.run(["echo", "Hello!"]),
      { resources: { cpu: "1", memory: "1Gi" } },
    );
    console.log(result.stdout);
    ```

    `tsx` を使用して実行します。

    ```bash theme={"system"}
    npx --yes --package=tsx tsx hello.mts
    ```
  </Tab>
</Tabs>

`x-wandb-api-key` ヘッダー、`wandb_api_key` ストラテジー識別子、および TypeScript の `/wandb` エントリポイントは、Forge の認証に使用する現行の SDK 識別子です。これらの識別子は変更せず、記載どおりに使用してください。

<h3 id="coreweave-api-access-token">
  CoreWeave API アクセストークン
</h3>

**Sandbox User** ロールを付与する [Access Policy](https://console.coreweave.com/organization/iam/access-policies) の作成または更新を管理者に依頼してください。手順については、[アクセスポリシーを作成する](/security/iam/access-policies/manage#create-an-access-policy)を参照してください。

[Tokens](https://console.coreweave.com/tokens) ページで API アクセストークンを作成し、その **Token Secret** をコピーして、ターミナルで設定します。

```bash theme={"system"}
export CWSANDBOX_API_KEY="[API-ACCESS-TOKEN]"
```

<Tabs>
  <Tab title="Python">
    [`uv`](https://docs.astral.sh/uv/getting-started/installation/) をインストールしたうえで、次の内容を `hello.py` として保存します。

    ```python title="hello.py" theme={"system"}
    from cwsandbox import AuthStrategy, Sandbox

    with Sandbox.run(
        auth=AuthStrategy.COREWEAVE_API_KEY,
        resources={"cpu": "1", "memory": "1Gi"},
    ) as sandbox:
        print(sandbox.exec(["echo", "Hello!"]).result().stdout)
    ```

    Python 3.11 とサンドボックスクライアントを使用して実行します。これらがインストールされていない場合は、このコマンドによって自動的にインストールされます。

    ```bash theme={"system"}
    uv run --python 3.11 --with 'cwsandbox>=1.10.0' hello.py
    ```
  </Tab>

  <Tab title="TypeScript">
    Node.js 22 以降をインストールしたうえで、クライアントをインストールします。

    ```bash theme={"system"}
    npm install @coreweave/cwsandbox
    ```

    次の内容を `hello.mts` として保存します。

    ```typescript title="hello.mts" theme={"system"}
    import { createSandboxClientFromEnv } from "@coreweave/cwsandbox/node";

    const client = createSandboxClientFromEnv();
    const result = await client.withSandbox(
      async (sandbox) => sandbox.commands.run(["echo", "Hello!"]),
      { resources: { cpu: "1", memory: "1Gi" } },
    );
    console.log(result.stdout);
    ```

    `tsx` で実行します。

    ```bash theme={"system"}
    npx --yes --package=tsx tsx hello.mts
    ```
  </Tab>
</Tabs>

<h3 id="verify-the-result">
  結果を確認する
</h3>

このサンプルを実行すると次の出力が表示され、処理の完了時にサンドボックスが停止します。

```text title="Output" theme={"system"}
Hello!
```

このサンドボックスには 1 CPU と 1 GiB のメモリが割り当てられています。サーバーレスでは、リソースの制限値はリクエスト値と同じに設定されます。CPU とメモリを変更するには、`resources` を変更します。

同時実行数のクォータ、作成リクエストのレート制限、クォータエラーについては、[制限とクォータ](/ja/products/sandboxes/reference/limits-and-quotas)を参照してください。

<h2 id="next-steps">
  次のステップ
</h2>

<span id="choose-a-placement-mode" />

<span id="spill-over-between-modes" />

<span id="deploy-sandboxes-on-your-own-cks-cluster" />

ワークロードに応じて、以下のガイドに進んでください。

* [独自のコンピュートを使用する](/ja/products/sandboxes/get-started-cks): クラスターでランナーを有効にし、そのクラスター上でサンドボックスを実行します。
* [サンドボックスの配置とスピルオーバー](/ja/products/sandboxes/placement): サーバーレスと CKS のキャパシティを比較し、フォールバックを設定します。
* [コーディングエージェントを実行する](/ja/products/sandboxes/agents): コーディングエージェントをサンドボックスに接続します。
* [GPU サンドボックス](/ja/products/sandboxes/gpu-sandboxes): GPU へのアクセスをリクエストし、GPU ワークロードを実行します。
* [Python クライアント](/ja/products/sandboxes/client): コマンドの実行、ファイルの操作、サンドボックスの設定を行います。
