E2B icon

E2B

Run commands and manage E2B sandboxes and snapshots

Code → Run Command

AI-generated

Summary

Run a shell command in an existing E2B sandbox or create a new temporary sandbox for this execution and run the command inside it.

Inputs

  • Sandbox ID — ID of an existing sandbox to run the command in, or leave empty to create a new sandbox.
  • Command (required) — The shell command to execute inside the sandbox.
  • Working Directory — Optional working directory path inside the sandbox where the command runs.
  • Template or Snapshot ID — Optional E2B template or snapshot ID to use when creating a new sandbox.
  • Metadata — JSON metadata to attach when creating a new sandbox.
  • Environment Variables — JSON object of environment variables to set for the sandbox or command.
  • Allow Internet Access — Boolean flag whether to allow internet access in the sandbox (default true).
  • Volume Mounts — JSON object mapping sandbox mount paths to E2B volume names, e.g. {"/data":"my-volume"}.
  • Kill Sandbox After Run — Boolean to kill the sandbox after running the command (default false).
  • Timeout — Timeout in seconds for the command execution (default 300 seconds).

Output shape

a single record

Returns a JSON object including sandbox ID, domain, command run, success flag, exit code, standard output and error, error messages if any, execution time, and flags indicating whether a sandbox was created or killed after run. Throws errors on command failure or sandbox kill failure when applicable.

Links

Discussion