---
lang: en
title: 'API docs: testlab.testsandbox._constructor_'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/testlab
permalink: /doc/en/lb4/apidocs.testlab.testsandbox._constructor_.html
---

<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@loopback/testlab](./testlab.md) &gt; [TestSandbox](./testlab.testsandbox.md) &gt; [(constructor)](./testlab.testsandbox._constructor_.md)

## TestSandbox.(constructor)

Will create a directory if it doesn't already exist. If it exists, you still get an instance of the TestSandbox.

**Signature:**

```typescript
constructor(rootPath: string, options?: TestSandboxOptions);
```

## Parameters

<table><thead><tr><th>

Parameter


</th><th>

Type


</th><th>

Description


</th></tr></thead>
<tbody><tr><td markdown="1">

rootPath


</td><td markdown="1">

string


</td><td markdown="1">

Root path of the TestSandbox. If relative it will be resolved against the current directory.


</td></tr>
<tr><td markdown="1">

options


</td><td markdown="1">

[TestSandboxOptions](./testlab.testsandboxoptions.md)


</td><td markdown="1">

_(Optional)_ Options to control if/how the sandbox creates a subdirectory for the sandbox. If not provided, the sandbox will automatically creates a unique temporary subdirectory. This allows sandboxes with the same root path can be used in parallel during testing.


</td></tr>
</tbody></table>

## Example


```ts
// Create a sandbox as a unique temporary subdirectory under the rootPath
const sandbox = new TestSandbox(rootPath);
const sandbox = new TestSandbox(rootPath, {subdir: true});

// Create a sandbox in the root path directly
// This is same as the old behavior
const sandbox = new TestSandbox(rootPath, {subdir: false});

// Create a sandbox in the `test1` subdirectory of the root path
const sandbox = new TestSandbox(rootPath, {subdir: 'test1'});
```


