> ## 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 SandboxBetaVersionWarning = () => {
  if (typeof document === "undefined") {
    return null;
  } else {
    return <Warning>The following legacy features require the legacy SDK and CLI versions listed in <Link href="/docs/ja/guides/sandbox-legacy-e2b-compatible" target="self">Legacy SDKs & CLI</Link>. Please note that legacy features may be less stable than production releases. If you encounter any issues while using these features, please <Link href="https://meetings-na2.hubspot.com/junyu" target="_blank">contact us</Link>.</Warning>;
  }
};

<Warning>
  このレガシーページは、1.x または beta SDK 系列を引き続き使用しているユーザー向けに保持されています。新しい SDK 2.x の統合では、現在の Sandbox ドキュメントに従ってください。
</Warning>

<SandboxBetaVersionWarning />

各 sandbox にタイムアウトを設定できます（[ライフサイクル管理](/docs/ja/guides/sandbox-lifecycle)を参照してください）。sandbox の実行時間がタイムアウトに達すると、sandbox は自動的に kill されます。ただし、一部のシナリオでは sandbox の想定実行時間を判断できない一方で、コスト削減のため、使用されていないときに sandbox を自動的に kill したい場合があります。この場合、\*\*「アイドルタイムアウト」\*\*機能を使用できます。

sandbox を作成する際、metadata 内で `idle_timeout` パラメータ（単位: 秒、最小値は 60）を設定することで、\*\*「アイドルタイムアウト」\*\*機能を有効にできます。有効にすると、指定された時間範囲内に sandbox で操作（コマンドの実行、コードの実行、ファイル操作など）がないことをシステムが検出した場合、システムはその sandbox インスタンスを kill します。それ以外の場合、sandbox は sandbox の稼働における最大時間制限（現在のデフォルトは 3600 秒）に達するまで実行され続けます。

次の例を参照してください。

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

  const sandbox = await Sandbox.create(
      {
          metadata: { "idle_timeout": "60" }
      }
  );
  console.log('Sandbox created', sandbox.sandboxId)

  const result = await sandbox.commands.run('ls -al')
  console.log('Command result', result)

  await new Promise(resolve => setTimeout(resolve, 90000));

  const isRunning = await sandbox.isRunning()
  console.log('Sandbox is running', isRunning)

  await sandbox.kill()
  ```

  ```python Python icon="python" theme={"system"}
  from novita_sandbox.core import Sandbox
  import time

  sandbox = Sandbox.create(
      metadata={"idle_timeout": "60"}  # Minimum time is 60s, you can customize it
  )
  print('Sandbox created', sandbox.sandbox_id)

  result = sandbox.commands.run('ls -al')
  print('Command result', result)

  print('Waiting for 90 seconds...')
  time.sleep(90)

  is_running = sandbox.is_running()
  print('Sandbox is running', is_running)

  sandbox.kill()
  ```
</CodeGroup>
