Skip to main content
POST
/
v1
/
agents
/
{agent_id}
/
sandbox
/
grep
Sandbox: Grep
curl --request POST \
  --url https://api.xpander.ai/v1/agents/{agent_id}/sandbox/grep \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '
{
  "pattern": "def main",
  "path": "src",
  "include": "*.py",
  "context_lines": 0
}
'
{
  "status": "ok",
  "stdout": "<string>",
  "stderr": "<string>",
  "exit_code": 123,
  "content": "<string>",
  "path": "<string>",
  "matches": [
    {}
  ],
  "url": "<string>",
  "error": "<string>"
}
Search for a regex pattern across files in the per-agent sandbox, with optional file-type filtering and surrounding context lines.

Path Parameters

agent_id
string
required
Agent ID (UUID)

Request Body

pattern
string
required
Regular expression to search for.
path
string
Directory or file path to search, relative to the sandbox root.
include
string
Optional filename glob to include (e.g. *.py).
context_lines
integer
default:0
Number of context lines to include before and after each match.

Response

status
string
Result status (e.g., ok).
matches
array
Array of match objects, each including the file path, matching line, and surrounding context.

Example Request

curl -X POST "https://api.xpander.ai/v1/agents/<agent-id>/sandbox/grep" \
  -H "Content-Type: application/json" \
  -H "x-api-key: <your-api-key>" \
  -d '{
    "pattern": "def main",
    "path": "src",
    "include": "*.py",
    "context_lines": 2
  }'

Notes

  • pattern is a regex. Escape regex metacharacters if you want to match them literally.
  • Narrow the search with path and include for faster results on large sandboxes.

See Also

Authorizations

x-api-key
string
header
required

API Key for authentication

Path Parameters

agent_id
string
required

Agent UUID

Body

application/json

Request body for regex search across files in the agent sandbox.

pattern
string
required

Regular expression to search for.

Example:

"def main"

path
string

Directory or file path to search, relative to the sandbox root.

Example:

"src"

include
string

Optional filename glob to include (e.g. *.py).

Example:

"*.py"

context_lines
integer
default:0

Number of context lines to include before and after each match.

Required range: x >= 0

Response

Successful Response

Generic response wrapper returned by agent sandbox endpoints. Not every field is populated for every tool.

status
string

Result status of the sandbox operation.

Example:

"ok"

stdout
string | null

Standard output captured from the sandbox command. Present for bash.

stderr
string | null

Standard error captured from the sandbox command. Present for bash.

exit_code
integer | null

Process exit code returned by the sandbox. Present for bash.

content
string | null

File contents. Present for file_read.

path
string | null

File path affected by the operation. Present for file_write, file_edit, multi_edit, file_share.

matches
Matches · object[] | null

Match results. Present for glob and grep.

url
string<uri> | null

Public CDN URL. Present for file_share.

error
string | null

Error message when the operation fails.