Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon What are the key differences between a sandbox instance and a regular instance in Octane


What are the key differences between a sandbox instance and a regular instance in Octane


In Laravel Octane, the key differences between a sandbox instance and a regular instance are:

Sandbox Instance

1. Cloned Application Instance: Octane clones the original application instance to create a sandbox instance for each incoming request. This ensures that each request has its own isolated environment, preventing state persistence issues between requests.
2. Clean Configuration: The sandbox instance includes a clean copy of the configuration repository, which is cloned from the fresh sandbox instance. This ensures that any mutations to the configurations only affect the sandbox.
3. Flushed Cache and Session: The sandbox instance flushes the cache and session state to prevent any data from persisting across requests.
4. Localized Translator: The sandbox instance sets the locales inside the translator to the original locales to ensure that the translator is reset for each request.
5. Auth Forget Guards: The sandbox instance forgets any guards that were set during previous requests to ensure a clean state.

Regular Instance

1. Original Application Instance: The regular instance is the original application instance, which persists across requests.
2. Persistent Configuration: The regular instance uses the original configuration repository, which can lead to state persistence issues between requests.
3. Persistent Cache and Session: The regular instance does not flush the cache and session state, allowing data to persist across requests.
4. No Localized Translator: The regular instance does not reset the translator locales, which can lead to issues if the application relies on locale-specific settings.
5. Persistent Auth Guards: The regular instance does not forget any guards that were set during previous requests, which can lead to security issues if not properly managed.

Best Practices

1. Avoid Passing Application Instance: Avoid passing the application instance directly to services or singletons. Instead, use the `app()` helper or `Container::getInstance()` to ensure that the correct instance is used.
2. Use Callbacks: Use callbacks to return the sandbox instance instead of passing the application instance directly.

By understanding these differences and following best practices, you can ensure that your application runs efficiently and securely with Octane[1][5].

Citations:
[1] https://www.getoctane.io/sandbox
[2] https://salesforce.stackexchange.com/questions/42163/performance-difference-between-sandbox-and-production-instances
[3] https://otoy1473900221.zendesk.com/hc/en-us/articles/115001577606-Instances
[4] https://blog.octanesolutions.com.au/sandbox-analysis.delivered
[5] https://divinglaravel.com/laravel-octane-bootstrapping-the-application-and-handling-requests