> For the complete documentation index, see [llms.txt](https://docs.computesdk.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.computesdk.com/providers/secure-exec.md).

# Secure Exec

Secure execution provider for ComputeSDK — a local, isolated sandbox using [secure-exec](https://www.npmjs.com/package/secure-exec)'s V8 isolates, with an in-memory filesystem. No remote service or credentials required.

## Installation & Setup

```bash
npm install @computesdk/secure-exec
```

There are no credentials to configure — sandboxes run locally in a V8 isolate.

> **Platform requirement:** the underlying V8 runtime binary (`secure-exec-v8`) is currently only available for **linux-x64**. `create()` throws on other platforms.

## Usage

```typescript
import { secureExec } from '@computesdk/secure-exec';

const compute = secureExec({
  memoryLimitMb: 128,
  cpuTimeLimitMs: 30_000,
});

// Create sandbox
const sandbox = await compute.sandbox.create();

// Run a command
const result = await sandbox.runCommand('echo "Hello from Secure-Exec!"');
console.log(result.stdout); // "Hello from Secure-Exec!"

// Clean up
await sandbox.destroy();
```

### Configuration Options

```typescript
interface SecureExecConfig {
  /** Memory cap for the V8 isolate in MB. Default: 128 */
  memoryLimitMb?: number;
  /** CPU time budget per exec call in ms. Default: 30_000 */
  cpuTimeLimitMs?: number;
  /** Allowlist of commands sandboxed code can spawn. Default: all allowed */
  allowedCommands?: string[];
}
```

### Supported Operations

| Method       | Supported | Notes                                                                              |
| ------------ | --------- | ---------------------------------------------------------------------------------- |
| `create`     | ✅         | Spins up a local V8 isolate with an in-memory filesystem rooted at `/workspace`.   |
| `getById`    | ❌         | Always returns `null` — sandboxes are in-process and not addressable across calls. |
| `list`       | ❌         | Always returns an empty array.                                                     |
| `destroy`    | no-op     | Nothing to tear down remotely.                                                     |
| `runCommand` | ✅         | Executes shell commands inside the isolate via `spawnSync`.                        |
| `getInfo`    | ✅         | Reports `metadata: { local: true }`.                                               |
| `getUrl`     | ❌         | Throws — `getUrl is not supported by secure-exec provider.`                        |
| `filesystem` | ✅         | Backed by secure-exec's in-memory filesystem (not shell-based).                    |

### Notes

* This provider is **local-only**: sandboxes live in the current Node process, so `getById` and `list` do not return anything and `destroy` is a no-op.
* Commands sandboxed code may spawn can be restricted with `allowedCommands`; by default all commands are allowed.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.computesdk.com/providers/secure-exec.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
