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

サンドボックスインスタンスが現在は不要だが、後でいつでも再開できる必要がある場合は、サンドボックスインスタンスを手動で一時停止および再開する方法について [ドキュメント](/docs/ja/guides/sandbox-legacy-persistence) を参照できます。

**「自動一時停止と再開」** 機能を使用すると、サンドボックスインスタンスは [タイムアウト](/docs/ja/guides/sandbox-lifecycle) 後に自動的に一時停止し、必要なときに再開できます。一時停止中のサンドボックスに対して操作（コマンドの実行、コードの実行、ファイル操作など）を実行しようとすると、手動操作なしで自動的に再開されます。

## 自動一時停止を有効にする

サンドボックスインスタンスの作成時に `auto_pause` パラメーターを `true` に設定することで、自動一時停止機能を有効にできます。サンドボックスインスタンスはタイムアウト後に自動的に一時停止し、後で再開できます。

<Warning>
  注: 再開されたサンドボックスインスタンスでも自動一時停止機能は有効なままであり、タイムアウト後に再び自動的に一時停止します。
</Warning>

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

  const sandbox = await Sandbox.create(
      {
          timeoutMs: 5_000,
          autoPause: true
      },
  );
  console.log('Sandbox created', sandbox.sandboxId)

  console.log('Waiting for 10 seconds...')
  await new Promise(resolve => setTimeout(resolve, 10000));

  const resumedSandbox = await Sandbox.connect(sandbox.sandboxId)
  console.log('Sandbox resumed', resumedSandbox.sandboxId)

  await sandbox.kill()
  ```

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

  sandbox = Sandbox.create(
      timeout=5,
      auto_pause=True,
  )
  print('Sandbox created', sandbox.sandbox_id)

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

  resumed_sandbox = Sandbox.connect(sandbox.sandbox_id)
  print('Sandbox resumed', resumed_sandbox.sandbox_id)

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

## 自動再開を有効にする

サンドボックスインスタンスの作成時に `metadata` の `auto_resume` キーを `true` に設定することで、自動再開機能を有効にできます。有効にすると、一時停止中のサンドボックスに対して操作（コマンドの実行、コードの実行、ファイル操作など）を行おうとしたときに、サンドボックスが自動的に再開されます。

<Warning>
  注: 再開されたサンドボックスのデフォルトのタイムアウトは 5 分です。`setTimeout` または `set_timeout` メソッドを使用して、サンドボックスのタイムアウトを更新できます。
</Warning>

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

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

  await sandbox.betaPause()
  console.log('Sandbox paused', sandbox.sandboxId)

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

  await sandbox.kill()
  ```

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

  sandbox = Sandbox.create(
      metadata={
          "auto_resume": "true",
      }
  )
  print('Sandbox created', sandbox.sandbox_id)

  sandbox.beta_pause()
  print('Sandbox paused', sandbox.sandbox_id)

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

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