Skip to main content
POST
/
v1
/
agents
/
{agent_id}
/
sandbox
/
file_edit
Sandbox: File Edit
curl --request POST \
  --url https://api.xpander.ai/v1/agents/{agent_id}/sandbox/file_edit \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '
{
  "path": "app.py",
  "old_text": "DEBUG = True",
  "new_text": "DEBUG = False"
}
'
{
  "status": "ok",
  "stdout": "<string>",
  "stderr": "<string>",
  "exit_code": 123,
  "content": "<string>",
  "path": "<string>",
  "matches": [
    {}
  ],
  "url": "<string>",
  "error": "<string>"
}
Edit a file in the per-agent sandbox by replacing an exact text occurrence. old_text must match the existing file content exactly, including whitespace and indentation.

Path Parameters

agent_id
string
required
Agent ID (UUID)

Request Body

path
string
required
Path to the file to edit, relative to the sandbox root.
old_text
string
required
Exact text to find and replace. Must match existing file content, including whitespace.
new_text
string
required
Replacement text. Use an empty string to delete the matched content.

Response

status
string
Result status (e.g., ok).
path
string
Path of the file that was edited.

Example Request

curl -X POST "https://api.xpander.ai/v1/agents/<agent-id>/sandbox/file_edit" \
  -H "Content-Type: application/json" \
  -H "x-api-key: <your-api-key>" \
  -d '{
    "path": "app.py",
    "old_text": "DEBUG = True",
    "new_text": "DEBUG = False"
  }'

Notes

  • The match is exact and case-sensitive. If old_text appears more than once in the file, the request fails — include additional surrounding context in old_text to make the match unique.
  • To apply several edits atomically, use Sandbox: Multi Edit instead.

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 editing a file in the agent sandbox by replacing exact text occurrences.

path
string
required

Path to the file to edit, relative to the sandbox root.

Example:

"app.py"

old_text
string
required

Exact text to find and replace. Must match existing file content, including whitespace.

Example:

"DEBUG = True"

new_text
string
required

Replacement text. Use an empty string to delete the matched content.

Example:

"DEBUG = False"

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.